Skip to content
This repository has been archived by the owner on Dec 3, 2023. It is now read-only.

Commit

Permalink
Print more trace info.
Browse files Browse the repository at this point in the history
  • Loading branch information
erikogenvik committed Oct 27, 2023
1 parent 929fd6d commit d0d0163
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
20 changes: 17 additions & 3 deletions src/squall/core/Generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ GenerateResult Generator::process(size_t filesToProcess) {
currentDirectoryPath = mSourceDirectory;
}

auto containedNewData = std::any_of(lastEntries.begin(), lastEntries.end(),[](const GenerateEntry& entry) {return entry.status == GenerateFileStatus::Copied;});
auto containedNewData = std::any_of(lastEntries.begin(), lastEntries.end(), [](const GenerateEntry& entry) { return entry.status == GenerateFileStatus::Copied; });

auto processedEntry = processDirectory(currentDirectoryPath, manifest, containedNewData);
mGeneratedEntries.emplace_back(processedEntry);
Expand Down Expand Up @@ -108,8 +108,15 @@ GenerateEntry Generator::processFile(const std::filesystem::path& filePath) {
auto relativePath = std::filesystem::relative(filePath, mSourceDirectory);
auto existingI = mConfig.existingEntries.find(relativePath);
if (existingI != mConfig.existingEntries.end()) {
if (existingI->second.lastWriteTime >= std::filesystem::last_write_time(filePath)) {
auto fileLastWriteTime = std::filesystem::last_write_time(filePath);
if (existingI->second.lastWriteTime >= fileLastWriteTime) {
spdlog::trace("Last write time for file {} was the same ({}), marking as unchanged.", filePath.string(),
std::chrono::clock_cast<std::chrono::system_clock>(fileLastWriteTime).time_since_epoch().count());
return {.fileEntry = existingI->second.fileEntry, .sourcePath=filePath, .repositoryPath=existingI->second.repositoryPath, .status = GenerateFileStatus::Existed};
} else {
spdlog::trace("Last write time for file {} ({}) differed from what was stored in the repo ({}), marking as changed.", filePath.string(),
std::chrono::clock_cast<std::chrono::system_clock>(fileLastWriteTime).time_since_epoch().count(),
std::chrono::clock_cast<std::chrono::system_clock>(existingI->second.lastWriteTime).time_since_epoch().count());
}
}
}
Expand All @@ -127,8 +134,15 @@ GenerateEntry Generator::processDirectory(const std::filesystem::path& filePath,
auto relativePath = std::filesystem::relative(filePath, mSourceDirectory) / "";
auto existingI = mConfig.existingEntries.find(relativePath);
if (existingI != mConfig.existingEntries.end()) {
if (existingI->second.lastWriteTime >= std::filesystem::last_write_time(filePath)) {
auto fileLastWriteTime = std::filesystem::last_write_time(filePath);
if (existingI->second.lastWriteTime >= fileLastWriteTime) {
spdlog::trace("Last write time for directory {} was the same ({}), marking as unchanged.", filePath.string(),
std::chrono::clock_cast<std::chrono::system_clock>(fileLastWriteTime).time_since_epoch().count());
return {.fileEntry = existingI->second.fileEntry, .sourcePath=filePath, .repositoryPath=existingI->second.repositoryPath, .status = GenerateFileStatus::Existed};
} else {
spdlog::trace("Last write time for directory {} ({}) differed from what was stored in the repo ({}), marking as changed.", filePath.string(),
std::chrono::clock_cast<std::chrono::system_clock>(fileLastWriteTime).time_since_epoch().count(),
std::chrono::clock_cast<std::chrono::system_clock>(existingI->second.lastWriteTime).time_since_epoch().count());
}
}
}
Expand Down
8 changes: 7 additions & 1 deletion tests/GeneratorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,12 @@ std::ostream& operator<<(std::ostream& os, std::pair<std::string, Squall::Genera
#include <catch2/matchers/catch_matchers_vector.hpp>
#include <utility>
#include <algorithm>
#include <spdlog/spdlog.h>

using namespace Squall;

TEST_CASE("Generator creates signatures", "[generator]") {
spdlog::set_level(spdlog::level::trace);
setupEncodings();

//For our test we use an empty directory. However, this can't be stored in Git so we need to instead copy the data to a temporary directory and create the empty directory there.
Expand Down Expand Up @@ -85,6 +87,7 @@ TEST_CASE("Generator creates signatures", "[generator]") {
}

TEST_CASE("Generator excludes if specified", "[generator]") {
spdlog::set_level(spdlog::level::trace);
setupEncodings();

Repository repository("GeneratorExcludeTestDirectory");
Expand Down Expand Up @@ -112,6 +115,7 @@ TEST_CASE("Generator excludes if specified", "[generator]") {


TEST_CASE("Generator includes if specified", "[generator]") {
spdlog::set_level(spdlog::level::trace);
setupEncodings();

Repository repository("GeneratorIncludeTestDirectory");
Expand All @@ -136,7 +140,7 @@ TEST_CASE("Generator includes if specified", "[generator]") {
}

TEST_CASE("Generator can read existing entries", "[generator]") {

spdlog::set_level(spdlog::level::trace);
setupEncodings();

std::filesystem::path repoPath = TESTDATADIR "/repo";
Expand All @@ -156,6 +160,7 @@ TEST_CASE("Generator can read existing entries", "[generator]") {
}

TEST_CASE("Generator ignores existing entries if specified", "[generator]") {
spdlog::set_level(spdlog::level::trace);
setupEncodings();

Repository repository("GeneratorIgnoreExistingTestDirectory");
Expand Down Expand Up @@ -191,6 +196,7 @@ TEST_CASE("Generator ignores existing entries if specified", "[generator]") {
}

TEST_CASE("Generator ignores existing entries if specified, but updates with new", "[generator]") {
spdlog::set_level(spdlog::level::trace);
setupEncodings();

//We will alter the data, so we need to first copy it to a temp directory.
Expand Down

0 comments on commit d0d0163

Please sign in to comment.