AuroraRuntime/Source/IO/FS/FSTimes.NT.cpp
Jamie Reece Wilson 83f34b0c47 [*] I was right. String views are [mostly] pointless (*)
03:28:55:638  17>2 of 53388 functions (<0.1%) were compiled, the rest were copied from previous compilation.
03:28:55:638  17>  0 functions were new in current compilation
03:28:55:638  17>  65 functions had inline decision re-evaluated but remain unchanged
03:28:56:749  17>Finished generating code

the header of const AuString & is the same as std::string_view therefore nothing changes. in fact, we still need to alloc strings a bunch of times for a zero terminated string. worse, <c++20 always allocs each time we want to access a hashmap with o(1) lookup, making small hashmaps kinda pointless when we always have to alloc+copy (thx std)

perhaps this will help some language binders
2024-04-19 05:58:08 +01:00

102 lines
2.8 KiB
C++

/***
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: FSTimes.NT.cpp
Date: 2023-2-4
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "FS.hpp"
#include "FSTimes.NT.hpp"
#include <Source/Time/Time.hpp>
namespace Aurora::IO::FS
{
const FILETIME *ConvertFileTime(FILETIME *temp, AuOptionalEx<AuInt64> time)
{
if (!time)
{
return nullptr;
}
auto word = AuTime::ConvertTimestampNs(time.value());
temp->dwLowDateTime = AuBitsToLower(word);
temp->dwHighDateTime = AuBitsToHigher(word);
return temp;
}
AUKN_SYM bool UpdateFileTimes(const AuROString &path, const UpdateTimes &times)
{
HANDLE hFile;
FILETIME created;
FILETIME modified;
FILETIME access;
if (path.empty())
{
SysPushErrorArg("Empty path provided");
return false;
}
auto pathex = NormalizePathRet(path);
if (pathex.empty())
{
SysPushErrorMemory();
return false;
}
auto win32Path = Locale::ConvertFromUTF8(pathex);
if (win32Path.empty())
{
return false;
}
hFile = Win32Open(win32Path.c_str(),
GENERIC_WRITE | FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES,
FILE_SHARE_READ | FILE_SHARE_WRITE,
false,
OPEN_EXISTING,
0,
0);
if (hFile == INVALID_HANDLE_VALUE)
{
if (!AuFS::FileExists(pathex))
{
SysPushErrorResourceMissing("Missing file: {}", path);
return false;
}
if (GetLastError() == ERROR_SHARING_VIOLATION)
{
RuntimeWaitForSecondaryTick();
hFile = Win32Open(win32Path.c_str(),
GENERIC_WRITE | FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES,
FILE_SHARE_READ | FILE_SHARE_WRITE,
false,
OPEN_EXISTING,
0,
0);
}
}
if (hFile == INVALID_HANDLE_VALUE)
{
SysPushErrorIO("Couldn't open a handle for: {}", path);
return false;
}
bool bRet = ::SetFileTime(hFile,
ConvertFileTime(&created, times.createdNs),
ConvertFileTime(&access, times.accessedNs),
ConvertFileTime(&modified, times.modifiedNs));
if (!bRet)
{
SysPushErrorIO();
}
AuWin32CloseHandle(hFile);
return bRet;
}
}