Skip to content

Commit

Permalink
Define testhelpers::setModificationDate for Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
luc-guyot-infomaniak committed Nov 18, 2024
1 parent 5038549 commit e8e553d
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions test/test_utility/testhelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@

#include "libcommon/utility/utility.h"

#include <time.h>
#include <utime.h>
#include <fstream>


#if defined(__APPLE__) || defined(__unix__)
#ifdef _WIN32
#include "libcommonserver/io/iohelper.h"
#else
#include <sys/stat.h>
#endif

Expand Down Expand Up @@ -60,19 +60,32 @@ std::string loadEnvVariable(const std::string& key) {
}
return val;
}
#ifdef _WIN32
void setModificationDate(const SyncPath& path, const std::chrono::time_point<std::chrono::system_clock>& timePoint) {
struct _utimebuf timeBuffer;
const std::time_t timeInSeconds = std::chrono::system_clock::to_time_t(timePoint);

IoError ioError = IoError::Success;
FileStat fileStat;
IoHelper::getFileStat(path, &fileStat, ioError);

timeBuffer.tma = fileStat.creationTime;
timeBuffer.tmm = timeInSeconds;
_utime(path.c_str(), &timeBuffer);
}
#else
void setModificationDate(const SyncPath& path, const std::chrono::time_point<std::chrono::system_clock>& timePoint) {
struct stat fileStat;
struct utimbuf new_times;
struct utimbuf newTime;

const auto fileNameStr = path.string();
const auto fileName = fileNameStr.c_str();

stat(fileName, &fileStat);

const std::time_t timeInSeconds = std::chrono::system_clock::to_time_t(timePoint);
new_times.modtime = timeInSeconds;
utime(fileName, &new_times);
newTime.modtime = timeInSeconds;
utime(fileName, &newTime);
}

#endif
} // namespace KDC::testhelpers

0 comments on commit e8e553d

Please sign in to comment.