diff options
| author | Dan Engelbrecht <[email protected]> | 2025-03-31 11:30:28 +0200 |
|---|---|---|
| committer | GitHub Enterprise <[email protected]> | 2025-03-31 11:30:28 +0200 |
| commit | ebe13120c030f8d24c5f05c068d79b2f72fc3c0b (patch) | |
| tree | 307f037113a64d47dc9f6ac9d1d9eb0ac20fd527 /src/zencore/filesystem.cpp | |
| parent | long filename support (#330) (diff) | |
| download | zen-ebe13120c030f8d24c5f05c068d79b2f72fc3c0b.tar.xz zen-ebe13120c030f8d24c5f05c068d79b2f72fc3c0b.zip | |
multithreaded clean (#331)
- Improvement: Faster cleaning of directories
- Improvement: Faster initial scanning of local state
Diffstat (limited to 'src/zencore/filesystem.cpp')
| -rw-r--r-- | src/zencore/filesystem.cpp | 55 |
1 files changed, 51 insertions, 4 deletions
diff --git a/src/zencore/filesystem.cpp b/src/zencore/filesystem.cpp index 6ff4dd053..4ec563ba3 100644 --- a/src/zencore/filesystem.cpp +++ b/src/zencore/filesystem.cpp @@ -280,16 +280,17 @@ bool RemoveFileNative(const std::filesystem::path& Path, bool ForceRemoveReadOnlyFiles, std::error_code& Ec) { #if ZEN_PLATFORM_WINDOWS - BOOL Success = ::DeleteFile(Path.native().c_str()); + const std::filesystem::path::value_type* NativePath = Path.native().c_str(); + BOOL Success = ::DeleteFile(NativePath); if (!Success) { if (ForceRemoveReadOnlyFiles) { - DWORD FileAttributes = ::GetFileAttributes(Path.native().c_str()); + DWORD FileAttributes = ::GetFileAttributes(NativePath); if ((FileAttributes != INVALID_FILE_ATTRIBUTES) && IsFileAttributeReadOnly(FileAttributes) != 0) { - ::SetFileAttributes(Path.native().c_str(), MakeFileAttributeReadOnly(FileAttributes, false)); - Success = ::DeleteFile(Path.native().c_str()); + ::SetFileAttributes(NativePath, MakeFileAttributeReadOnly(FileAttributes, false)); + Success = ::DeleteFile(NativePath); } } if (!Success) @@ -1964,6 +1965,52 @@ GetModificationTickFromPath(const std::filesystem::path& Filename) #endif } +bool +TryGetFileProperties(const std::filesystem::path& Path, + uint64_t& OutSize, + uint64_t& OutModificationTick, + uint32_t& OutNativeModeOrAttributes) +{ +#if ZEN_PLATFORM_WINDOWS + const std::filesystem::path::value_type* NativePath = Path.native().c_str(); + { + void* Handle = CreateFileW(NativePath, + GENERIC_READ, + FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, + nullptr, + OPEN_EXISTING, + 0, + nullptr); + if (Handle == INVALID_HANDLE_VALUE) + { + return false; + } + auto _ = MakeGuard([Handle]() { CloseHandle(Handle); }); + + BY_HANDLE_FILE_INFORMATION Bhfh = {}; + if (!GetFileInformationByHandle(Handle, &Bhfh)) + { + return false; + } + OutSize = uint64_t(Bhfh.nFileSizeHigh) << 32 | Bhfh.nFileSizeLow; + OutModificationTick = ((uint64_t(Bhfh.ftLastWriteTime.dwHighDateTime) << 32) | Bhfh.ftLastWriteTime.dwLowDateTime); + OutNativeModeOrAttributes = Bhfh.dwFileAttributes; + return true; + } +#else + struct stat Stat; + int err = stat(Path.native().c_str(), &Stat); + if (err) + { + return false; + } + OutModificationTick = gsl::narrow<uint64_t>(Stat.st_mtime); + OutSize = size_t(Stat.st_size); + OutNativeModeOrAttributes = (uint32_t)Stat.st_mode; + return true; +#endif +} + void RenameFile(const std::filesystem::path& SourcePath, const std::filesystem::path& TargetPath) { |