2023-02-04 19:43:01 +00:00
|
|
|
/***
|
|
|
|
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
|
|
|
|
|
|
|
|
File: FSTimes.Unix.cpp
|
|
|
|
Date: 2023-2-4
|
|
|
|
Author: Reece
|
|
|
|
***/
|
|
|
|
#include <Source/RuntimeInternal.hpp>
|
|
|
|
#include "FS.hpp"
|
|
|
|
#include "FSTimes.Unix.hpp"
|
|
|
|
#include <Source/Time/Time.hpp>
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <utime.h>
|
|
|
|
|
|
|
|
namespace Aurora::IO::FS
|
|
|
|
{
|
|
|
|
void ConvertFileTime(timeval *temp,
|
|
|
|
AuInt64 alternative,
|
|
|
|
AuOptionalEx<AuInt64> time)
|
|
|
|
{
|
|
|
|
timespec ts;
|
|
|
|
|
|
|
|
if (!time)
|
|
|
|
{
|
|
|
|
time = alternative;
|
|
|
|
}
|
|
|
|
|
|
|
|
AuTime::auabsns2ts(&ts, time.value());
|
|
|
|
|
|
|
|
temp->tv_sec = ts.tv_sec;
|
|
|
|
temp->tv_usec = ts.tv_nsec / 1'000ull;
|
|
|
|
}
|
|
|
|
|
|
|
|
AUKN_SYM bool UpdateFileTimes(const AuString &path, const UpdateTimes ×)
|
|
|
|
{
|
|
|
|
if (times.createdNs)
|
|
|
|
{
|
|
|
|
SysPushErrorArg("Cannot modify a files' created timestamp under UNIX");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto pathex = NormalizePathRet(path);
|
|
|
|
if (pathex.empty())
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2024-01-09 05:08:54 +00:00
|
|
|
RuntimeWaitForSecondaryTick();
|
|
|
|
|
2023-02-04 19:43:01 +00:00
|
|
|
Stat auStat;
|
|
|
|
if (!times.accessedNs ||
|
|
|
|
!times.modifiedNs)
|
|
|
|
{
|
|
|
|
if (!AuFS::StatFile(pathex, auStat))
|
|
|
|
{
|
|
|
|
SysPushErrorArg("Cannot stat file of a attr-poke suspect");
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!AuFS::FileExists(pathex))
|
|
|
|
{
|
|
|
|
SysPushErrorIO("Missing file: {}", path);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
timeval timeVals[2];
|
|
|
|
|
2023-08-11 15:51:42 +00:00
|
|
|
ConvertFileTime(&timeVals[0], auStat.accessedNs, times.accessedNs);
|
|
|
|
ConvertFileTime(&timeVals[1], auStat.modifiedNs, times.modifiedNs);
|
2023-02-04 19:43:01 +00:00
|
|
|
|
|
|
|
bool bRet = ::utimes(pathex.c_str(), timeVals) == 0;
|
|
|
|
if (!bRet)
|
|
|
|
{
|
|
|
|
SysPushErrorIO();
|
|
|
|
}
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
}
|