diff --git a/src/common/file.cpp b/src/common/file.cpp index 90839a88e..0f0cda73f 100644 --- a/src/common/file.cpp +++ b/src/common/file.cpp @@ -445,45 +445,6 @@ bool File::SetLastAccessAndWriteTimeUTC(const std::filesystem::path& name, const return SysFileSetLastAccessAndWriteTimeUtc(name, af, wf); } -std::vector File::FindFiles(const std::filesystem::path& path) { - std::vector files; - - SysFileFindFiles(path, files); - - const auto normalized_path = path.lexically_normal(); - std::vector ret; - ret.reserve(files.size()); - - for (const auto& f: files) { - File::FindInfo r {}; - - r.path_with_name = f.path_with_name; - r.rel_path_with_name = f.path_with_name.lexically_normal().lexically_relative(normalized_path); - r.size = f.size; - - SysTimeStruct at {}; - SysTimeStruct wt {}; - - SysFileToSystemTimeUtc(f.last_access_time, at); - SysFileToSystemTimeUtc(f.last_write_time, wt); - - if (!at.is_invalid && !wt.is_invalid) { - r.last_access_time = DateTime(Date(at.Year, at.Month, at.Day), - Time(at.Hour, at.Minute, at.Second, at.Milliseconds)); - r.last_write_time = DateTime(Date(wt.Year, wt.Month, wt.Day), - Time(wt.Hour, wt.Minute, wt.Second, wt.Milliseconds)); - } - - // printf("%s, %s, %" PRIu64", %s, %s\n", r.path_with_name.c_str(), - // r.rel_path_with_name.c_str(), r.size, r.last_access_time.ToString().c_str(), - // r.last_write_time.ToString().c_str()); - - ret.push_back(std::move(r)); - } - - return ret; -} - std::vector File::GetDirEntries(const std::filesystem::path& path) { std::vector files; diff --git a/src/common/file.h b/src/common/file.h index 1428b4a18..73cdd53e4 100644 --- a/src/common/file.h +++ b/src/common/file.h @@ -30,14 +30,6 @@ class File { public: enum class Mode { Read, Write, ReadWrite, WriteRead }; - struct FindInfo { - std::filesystem::path path_with_name; - std::filesystem::path rel_path_with_name; - DateTime last_access_time; - DateTime last_write_time; - uint64_t size; - }; - struct DirEntry { std::string name; bool is_file; @@ -98,7 +90,6 @@ public: static bool SetLastAccessAndWriteTimeUTC(const std::filesystem::path& name, const DateTime& access, const DateTime& write); - static std::vector FindFiles(const std::filesystem::path& path); static std::vector GetDirEntries(const std::filesystem::path& path); static bool CopyFile(const std::filesystem::path& src, const std::filesystem::path& dst); static bool RenameFile(const std::filesystem::path& src, const std::filesystem::path& dst); diff --git a/src/common/platform/sysFileIO.h b/src/common/platform/sysFileIO.h index 6cca03a56..526d44d44 100644 --- a/src/common/platform/sysFileIO.h +++ b/src/common/platform/sysFileIO.h @@ -18,14 +18,6 @@ enum sys_file_cache_type_t { SYS_FILE_CACHE_SEQUENTIAL_SCAN = 2 // NOLINT(readability-identifier-naming) }; -// NOLINTNEXTLINE(readability-identifier-naming) -struct sys_file_find_t { - std::filesystem::path path_with_name; - SysFileTimeStruct last_access_time; - SysFileTimeStruct last_write_time; - uint64_t size; -}; - // NOLINTNEXTLINE(readability-identifier-naming) struct sys_dir_entry_t { std::string name; @@ -75,8 +67,6 @@ bool SysFileSetLastWriteTimeUtc(const std::filesystem::path& name, SysFileTimeSt bool SysFileSetLastAccessAndWriteTimeUtc(const std::filesystem::path& name, SysFileTimeStruct& access, SysFileTimeStruct& write); // NOLINTNEXTLINE(google-runtime-references) -void SysFileFindFiles(const std::filesystem::path& path, std::vector& out); -// NOLINTNEXTLINE(google-runtime-references) void SysFileGetDents(const std::filesystem::path& path, std::vector& out); bool SysFileCopyFile(const std::filesystem::path& src, const std::filesystem::path& dst); bool SysFileRenameFile(const std::filesystem::path& src, const std::filesystem::path& dst); diff --git a/src/common/platform/sysLinuxFileIO.cpp b/src/common/platform/sysLinuxFileIO.cpp index 38029296b..7605010e6 100644 --- a/src/common/platform/sysLinuxFileIO.cpp +++ b/src/common/platform/sysLinuxFileIO.cpp @@ -610,51 +610,6 @@ bool SysFileSetLastAccessAndWriteTimeUtc(const std::filesystem::path& name, // } } -// Recursively collect regular files. -void SysFileFindFiles(const std::filesystem::path& path, std::vector& out) { - auto real_path = get_internal_name(path); - - DIR* dir = opendir(real_path.string().c_str()); - if (dir == nullptr) { - return; - } - - for (const dirent* entry = readdir(dir); entry != nullptr; entry = readdir(dir)) { - const std::string file_name(entry->d_name); - - if (file_name == "." || file_name == "..") { - continue; - } - - auto child = real_path / file_name; - struct stat s {}; - - // lstat, so a symlink is never followed into a cycle during the recursive walk. - if (0 != lstat(child.string().c_str(), &s)) { - continue; - } - - if (S_ISDIR(s.st_mode)) { - SysFileFindFiles(child, out); - } else if (S_ISREG(s.st_mode)) { - sys_file_find_t r {}; - - r.path_with_name = child; - r.size = static_cast(s.st_size); - r.last_access_time.is_invalid = false; - r.last_access_time.time = s.st_atime; - r.last_access_time.nanos = KYTY_STAT_ATIME_NS(s); - r.last_write_time.is_invalid = false; - r.last_write_time.time = s.st_mtime; - r.last_write_time.nanos = KYTY_STAT_MTIME_NS(s); - - out.push_back(r); - } - } - - closedir(dir); -} - // Keep "." and ".." to match FindFirstFileW. void SysFileGetDents(const std::filesystem::path& path, std::vector& out) { auto real_path = get_internal_name(path); diff --git a/src/common/platform/sysWindowsFileIO.cpp b/src/common/platform/sysWindowsFileIO.cpp index 54fb202a1..d9ad9469f 100644 --- a/src/common/platform/sysWindowsFileIO.cpp +++ b/src/common/platform/sysWindowsFileIO.cpp @@ -476,46 +476,6 @@ bool SysFileSetLastAccessAndWriteTimeUtc(const std::filesystem::path& name, return ok; } -void SysFileFindFiles(const std::filesystem::path& path, std::vector& out) { - const auto pattern = path / L"*"; - - WIN32_FIND_DATAW data {}; - HANDLE h = FindFirstFileW(pattern.c_str(), &data); - - if (h == INVALID_HANDLE_VALUE) { - return; - } - - do { - std::filesystem::path file_name(data.cFileName); - - if (file_name == L"." || file_name == L"..") { - continue; - } - - const auto full_path = path / file_name; - - if ((data.dwFileAttributes & static_cast(FILE_ATTRIBUTE_DIRECTORY)) != 0u) { - SysFileFindFiles(full_path, out); - } else { - sys_file_find_t r {}; - - r.path_with_name = full_path; - r.size = (static_cast(data.nFileSizeHigh) << 32u) + - static_cast(data.nFileSizeLow); - r.last_access_time.is_invalid = false; - r.last_access_time.time = data.ftLastAccessTime; - r.last_write_time.is_invalid = false; - r.last_write_time.time = data.ftLastWriteTime; - - out.push_back(std::move(r)); - } - - } while (FindNextFileW(h, &data) != 0); - - FindClose(h); -} - void SysFileGetDents(const std::filesystem::path& path, std::vector& out) { const auto pattern = path / L"*"; diff --git a/tests/KernelFileSystemTests.cpp b/tests/KernelFileSystemTests.cpp index 290041416..bcf97112f 100644 --- a/tests/KernelFileSystemTests.cpp +++ b/tests/KernelFileSystemTests.cpp @@ -189,20 +189,6 @@ void CheckUnicodePaths(const std::filesystem::path &root) { Check(fixture.Create(native_file), "create Unicode filename"); fixture.Close(); - for (const auto &directory : {unicode_root, std::filesystem::relative(unicode_root)}) { - // A Windows temporary directory may be on a different drive from the working directory. - if (directory.empty()) { - continue; - } - const auto files = Common::File::FindFiles(directory); - const auto relative_file = - std::filesystem::path(u8"nested/asset-\u00e9-\u65e5\u672c\u8a9e.bin"); - Check(std::any_of(files.begin(), files.end(), [&](const auto &file) { - return file.path_with_name.lexically_normal() == - (directory / relative_file).lexically_normal() && - file.rel_path_with_name == relative_file; - }), "recursive enumeration preserves native and relative Unicode paths"); - } const auto entries = Common::File::GetDirEntries(nested_root); Check(std::any_of(entries.begin(), entries.end(), [&](const auto &entry) { return entry.is_file && entry.name == GuestFilename;