AuroraRuntime/Source/IO/FS/FSTimes.Unix.cpp
Reece Wilson f43251c8fc [+] AuNet::ISocketChannelEventListener
[+] AuFS::UpdateTimes
[+] AuFS::UpdateFileTimes
[+] AuFS::CompressEx
[*] AuFS::Compress now rejects files that look to be already compressed
[+] AuFS::DecompressEx
[+] AuFS::Create
[+] AuFS::WriteNewFile
[+] AuFS::WriteNewString
[+] AuFs::FileAttrsList
[+] AuFs::FileAttrsGet
[+] AuFs::FileAttrsSet
[+] DirectoryLogger::uMaxLogsOrZeroBeforeCompress
[+] ISocketChannel.AddEventListener
[+] ISocketChannel.AddEventListener
[+] DirectoryLogger.uMaxLogsOrZeroBeforeCompress
[*] Fix UNIX regression
[*] Fix up stream socket channel realloc IPC
[*] Fix shutdown regression in pretty much everything thanks to 8ff81df1's dumbass fix
    (fixes fence regression on shutdown)
[*] Fix DirDeleterEx formatting of reported failed paths
[*] Fix up file not truncated if already exists bugs. Extended and alternative apis added.
[*] Fix ICompressionStream::ReadEx returning the wrong read value
[+] Legacy compression API can now self-correct once newer stream processor objects are added
2023-02-04 19:43:01 +00:00

80 lines
1.9 KiB
C++

/***
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 &times)
{
if (times.createdNs)
{
SysPushErrorArg("Cannot modify a files' created timestamp under UNIX");
return false;
}
auto pathex = NormalizePathRet(path);
if (pathex.empty())
{
return false;
}
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];
ConvertFileTime(&timeVals[0], auStat.accessed, times.accessedNs);
ConvertFileTime(&timeVals[1], auStat.modified, times.modifiedNs);
bool bRet = ::utimes(pathex.c_str(), timeVals) == 0;
if (!bRet)
{
SysPushErrorIO();
}
return bRet;
}
}