From b5a99e7458ce9bda389dd7462e162d49621faa7d Mon Sep 17 00:00:00 2001 From: Kichin Egor Date: Mon, 21 Nov 2022 11:35:48 +0300 Subject: [PATCH 1/2] Refresh wrappers after change source files. --- server/src/Synchronizer.cpp | 26 ++++++++++++++++++++++---- server/src/Synchronizer.h | 4 +++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/server/src/Synchronizer.cpp b/server/src/Synchronizer.cpp index 16da3649..6a3e6f0e 100644 --- a/server/src/Synchronizer.cpp +++ b/server/src/Synchronizer.cpp @@ -44,7 +44,7 @@ Synchronizer::Synchronizer(BaseTestGen *testGen, : testGen(testGen), sizeContext(sizeContext) { } -bool Synchronizer::isProbablyOutdated(const fs::path &srcFilePath) const { +bool Synchronizer::isProbablyOutdatedStubs(const fs::path &srcFilePath) const { fs::path stubFilePath = Paths::sourcePathToStubPath(testGen->projectContext, srcFilePath); if (!fs::exists(stubFilePath)) { return true; @@ -64,16 +64,34 @@ bool Synchronizer::isProbablyOutdated(const fs::path &srcFilePath) const { return stubTimestamp <= srcTimestamp; } +bool Synchronizer::isProbablyOutdatedWrappers(const fs::path &srcFilePath) const { + fs::path wrapperFilePath = Paths::getWrapperFilePath(testGen->projectContext, srcFilePath); + if (!fs::exists(wrapperFilePath)) { + return true; + } + long long wrapperTimestamp, srcTimestamp; + + wrapperTimestamp = TimeUtils::convertFileToSystemClock(fs::last_write_time(wrapperFilePath)) + .time_since_epoch() + .count(); + srcTimestamp = TimeUtils::convertFileToSystemClock(fs::last_write_time(srcFilePath)) + .time_since_epoch() + .count(); + 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; } diff --git a/server/src/Synchronizer.h b/server/src/Synchronizer.h index 62d70661..ae0990cc 100644 --- a/server/src/Synchronizer.h +++ b/server/src/Synchronizer.h @@ -27,7 +27,9 @@ class Synchronizer { [[nodiscard]] std::unordered_set getOutdatedStubs() const; - bool isProbablyOutdated(const fs::path &srcFilePath) const; + bool isProbablyOutdatedStubs(const fs::path &srcFilePath) const; + + bool isProbablyOutdatedWrappers(const fs::path &srcFilePath) const; bool removeStubIfSourceAbsent(const StubOperator &stub) const; From 2a3631287a55564a845a68132921e85ac99e9290 Mon Sep 17 00:00:00 2001 From: Kichin Egor Date: Tue, 22 Nov 2022 14:04:07 +0300 Subject: [PATCH 2/2] Move similar code to function. --- server/src/Synchronizer.cpp | 19 +++++++++---------- server/src/Synchronizer.h | 2 ++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/server/src/Synchronizer.cpp b/server/src/Synchronizer.cpp index 6a3e6f0e..a659bea4 100644 --- a/server/src/Synchronizer.cpp +++ b/server/src/Synchronizer.cpp @@ -44,6 +44,12 @@ Synchronizer::Synchronizer(BaseTestGen *testGen, : testGen(testGen), sizeContext(sizeContext) { } +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)) { @@ -58,9 +64,7 @@ bool Synchronizer::isProbablyOutdatedStubs(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; } @@ -70,13 +74,8 @@ bool Synchronizer::isProbablyOutdatedWrappers(const fs::path &srcFilePath) const return true; } long long wrapperTimestamp, srcTimestamp; - - wrapperTimestamp = TimeUtils::convertFileToSystemClock(fs::last_write_time(wrapperFilePath)) - .time_since_epoch() - .count(); - srcTimestamp = TimeUtils::convertFileToSystemClock(fs::last_write_time(srcFilePath)) - .time_since_epoch() - .count(); + wrapperTimestamp = Synchronizer::getFileOutdatedTime(wrapperFilePath); + srcTimestamp = Synchronizer::getFileOutdatedTime(srcFilePath); return wrapperTimestamp <= srcTimestamp; } diff --git a/server/src/Synchronizer.h b/server/src/Synchronizer.h index ae0990cc..c7eb12fa 100644 --- a/server/src/Synchronizer.h +++ b/server/src/Synchronizer.h @@ -27,6 +27,8 @@ class Synchronizer { [[nodiscard]] std::unordered_set getOutdatedStubs() const; + long long getFileOutdatedTime(const fs::path &filePath) const; + bool isProbablyOutdatedStubs(const fs::path &srcFilePath) const; bool isProbablyOutdatedWrappers(const fs::path &srcFilePath) const;