Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions server/src/Synchronizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,13 @@ Synchronizer::Synchronizer(BaseTestGen *testGen,
: testGen(testGen), sizeContext(sizeContext) {
}

bool Synchronizer::isProbablyOutdated(const fs::path &srcFilePath) const {
long long Synchronizer::getFileOutdatedTime(const fs::path &filePath) const {
return TimeUtils::convertFileToSystemClock(fs::last_write_time(filePath))
.time_since_epoch()
.count();
}

bool Synchronizer::isProbablyOutdatedStubs(const fs::path &srcFilePath) const {
fs::path stubFilePath = Paths::sourcePathToStubPath(testGen->projectContext, srcFilePath);
if (!fs::exists(stubFilePath)) {
return true;
Expand All @@ -58,22 +64,33 @@ bool Synchronizer::isProbablyOutdated(const fs::path &srcFilePath) const {
} catch (...) {
return true;
}
srcTimestamp = TimeUtils::convertFileToSystemClock(fs::last_write_time(srcFilePath))
.time_since_epoch()
.count();
srcTimestamp = Synchronizer::getFileOutdatedTime(srcFilePath);
return stubTimestamp <= srcTimestamp;
}

bool Synchronizer::isProbablyOutdatedWrappers(const fs::path &srcFilePath) const {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move similar part into separate function

fs::path wrapperFilePath = Paths::getWrapperFilePath(testGen->projectContext, srcFilePath);
if (!fs::exists(wrapperFilePath)) {
return true;
}
long long wrapperTimestamp, srcTimestamp;
wrapperTimestamp = Synchronizer::getFileOutdatedTime(wrapperFilePath);
srcTimestamp = Synchronizer::getFileOutdatedTime(srcFilePath);
return wrapperTimestamp <= srcTimestamp;
}

CollectionUtils::FileSet Synchronizer::getOutdatedSourcePaths() const {
return CollectionUtils::filterOut(getTargetSourceFiles(), [this](fs::path const &sourcePath) {
return !isProbablyOutdated(sourcePath);
auto allFiles = getTargetSourceFiles();
auto outdatedSources = CollectionUtils::filterOut(getTargetSourceFiles(), [this](fs::path const &sourcePath) {
return !isProbablyOutdatedWrappers(sourcePath);
});
return outdatedSources;
}

StubSet Synchronizer::getOutdatedStubs() const {
auto allFiles = getStubsFiles();
auto outdatedStubs = CollectionUtils::filterOut(allFiles, [this](StubOperator const &stubOperator) {
return !isProbablyOutdated(stubOperator.getSourceFilePath());
return !isProbablyOutdatedStubs(stubOperator.getSourceFilePath());
});
return outdatedStubs;
}
Expand Down
6 changes: 5 additions & 1 deletion server/src/Synchronizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ class Synchronizer {

[[nodiscard]] std::unordered_set<StubOperator, HashUtils::StubHash> getOutdatedStubs() const;

bool isProbablyOutdated(const fs::path &srcFilePath) const;
long long getFileOutdatedTime(const fs::path &filePath) const;

bool isProbablyOutdatedStubs(const fs::path &srcFilePath) const;

bool isProbablyOutdatedWrappers(const fs::path &srcFilePath) const;

bool removeStubIfSourceAbsent(const StubOperator &stub) const;

Expand Down