From: Joel Rosdahl Date: Wed, 12 Jun 2024 18:20:25 +0000 (+0200) Subject: refactor: Convert some std::string paths to fs::path X-Git-Tag: v4.11~102 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=677a166fd0036d9d34b41fb3440e76634995d9df;p=thirdparty%2Fccache.git refactor: Convert some std::string paths to fs::path --- diff --git a/src/ccache/ccache.cpp b/src/ccache/ccache.cpp index f9ab687f..bd1e2cd5 100644 --- a/src/ccache/ccache.cpp +++ b/src/ccache/ccache.cpp @@ -890,7 +890,7 @@ update_manifest(Context& ctx, struct FindCoverageFileResult { bool found; - std::string path; + fs::path path; bool mangled; }; @@ -901,9 +901,9 @@ find_coverage_file(const Context& ctx) // (in CWD) if -fprofile-dir=DIR is present (regardless of DIR) instead of the // traditional /dir/to/example.gcno. - std::string mangled_form = core::Result::gcno_file_in_mangled_form(ctx); - std::string unmangled_form = core::Result::gcno_file_in_unmangled_form(ctx); - std::string found_file; + fs::path mangled_form = core::Result::gcno_file_in_mangled_form(ctx); + fs::path unmangled_form = core::Result::gcno_file_in_unmangled_form(ctx); + fs::path found_file; if (DirEntry(mangled_form).is_regular_file()) { LOG("Found coverage file {}", mangled_form); found_file = mangled_form; diff --git a/src/ccache/config.cpp b/src/ccache/config.cpp index e9e78dac..9e38994c 100644 --- a/src/ccache/config.cpp +++ b/src/ccache/config.cpp @@ -424,10 +424,10 @@ using ConfigLineHandler = std::function -read_from_path_or_stdin(const std::string& path) +read_from_path_or_stdin(const fs::path& path) { if (path == "-") { return util::read_fd(STDIN_FILENO).transform_error([&](auto error) { @@ -207,7 +207,7 @@ read_from_path_or_stdin(const std::string& path) } static int -inspect_path(const std::string& path) +inspect_path(const fs::path& path) { std::optional orig_dir_entry; if (path != "-") { diff --git a/src/ccache/core/result.cpp b/src/ccache/core/result.cpp index 701c9220..3599bb52 100644 --- a/src/ccache/core/result.cpp +++ b/src/ccache/core/result.cpp @@ -161,22 +161,19 @@ file_type_to_string(FileType type) return k_unknown_file_type; } -std::string +fs::path gcno_file_in_mangled_form(const Context& ctx) { const auto& output_obj = ctx.args_info.output_obj; - const std::string abs_output_obj = - output_obj.is_absolute() ? util::pstr(output_obj) - : FMT("{}/{}", ctx.apparent_cwd, output_obj); - std::string hashified_obj = abs_output_obj; + std::string hashified_obj = (ctx.apparent_cwd / output_obj).generic_string(); std::replace(hashified_obj.begin(), hashified_obj.end(), '/', '#'); - return util::pstr(util::with_extension(hashified_obj, ".gcno")); + return util::with_extension(hashified_obj, ".gcno"); } -std::string +fs::path gcno_file_in_unmangled_form(const Context& ctx) { - return util::pstr(util::with_extension(ctx.args_info.output_obj, ".gcno")); + return util::with_extension(ctx.args_info.output_obj, ".gcno"); } Deserializer::Deserializer(nonstd::span data) : m_data(data) diff --git a/src/ccache/core/result.hpp b/src/ccache/core/result.hpp index 6645feb6..2bf94222 100644 --- a/src/ccache/core/result.hpp +++ b/src/ccache/core/result.hpp @@ -97,8 +97,8 @@ enum class FileType : UnderlyingFileTypeInt { const char* file_type_to_string(FileType type); -std::string gcno_file_in_mangled_form(const Context& ctx); -std::string gcno_file_in_unmangled_form(const Context& ctx); +std::filesystem::path gcno_file_in_mangled_form(const Context& ctx); +std::filesystem::path gcno_file_in_unmangled_form(const Context& ctx); // This class knows how to deserializer a result cache entry. class Deserializer diff --git a/src/ccache/core/resultextractor.cpp b/src/ccache/core/resultextractor.cpp index 339df219..ed2cafaf 100644 --- a/src/ccache/core/resultextractor.cpp +++ b/src/ccache/core/resultextractor.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -32,12 +33,14 @@ #include +namespace fs = util::filesystem; + using util::DirEntry; namespace core { ResultExtractor::ResultExtractor( - const std::string& output_directory, + const fs::path& output_directory, std::optional get_raw_file_path) : m_output_directory(output_directory), m_get_raw_file_path(get_raw_file_path) @@ -58,7 +61,7 @@ ResultExtractor::on_embedded_file(uint8_t /*file_number*/, suffix.resize(suffix.length() - 1); } - const auto dest_path = FMT("{}/ccache-result{}", m_output_directory, suffix); + const auto dest_path = m_output_directory / FMT("ccache-result{}", suffix); util::throw_on_error(util::write_file(dest_path, data), FMT("Failed to write to {}: ", dest_path)); } diff --git a/src/ccache/core/resultextractor.hpp b/src/ccache/core/resultextractor.hpp index 50af8b9e..5be41a05 100644 --- a/src/ccache/core/resultextractor.hpp +++ b/src/ccache/core/resultextractor.hpp @@ -23,6 +23,7 @@ #include #include +#include #include #include #include @@ -33,12 +34,12 @@ namespace core { class ResultExtractor : public Result::Deserializer::Visitor { public: - using GetRawFilePathFunction = std::function; + using GetRawFilePathFunction = std::function; //`result_path` should be the path to the local result entry file if the // result comes from local storage. ResultExtractor( - const std::string& output_directory, + const std::filesystem::path& output_directory, std::optional get_raw_file_path = std::nullopt); void on_embedded_file(uint8_t file_number, @@ -49,7 +50,7 @@ public: uint64_t file_size) override; private: - std::string m_output_directory; + std::filesystem::path m_output_directory; std::optional m_get_raw_file_path; }; diff --git a/src/ccache/hash.cpp b/src/ccache/hash.cpp index 6aac5d3d..0fabb2a6 100644 --- a/src/ccache/hash.cpp +++ b/src/ccache/hash.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -33,6 +34,8 @@ # include #endif +namespace fs = util::filesystem; + const uint8_t HASH_DELIMITER[] = {0, 'c', 'C', 'a', 'C', 'h', 'E', 0}; Hash::Hash() @@ -99,9 +102,9 @@ Hash::hash_fd(int fd) } tl::expected -Hash::hash_file(const std::string& path) +Hash::hash_file(const fs::path& path) { - util::Fd fd(open(path.c_str(), O_RDONLY | O_BINARY)); + util::Fd fd(open(util::pstr(path).c_str(), O_RDONLY | O_BINARY)); if (!fd) { LOG("Failed to open {}: {}", path, strerror(errno)); return tl::unexpected(strerror(errno)); diff --git a/src/ccache/hash.hpp b/src/ccache/hash.hpp index 4a1b58b1..92e0a697 100644 --- a/src/ccache/hash.hpp +++ b/src/ccache/hash.hpp @@ -82,7 +82,7 @@ public: // // If hash debugging is enabled, the data is written verbatim to the text // input file. - tl::expected hash_file(const std::string& path); + tl::expected hash_file(const std::filesystem::path& path); // Add contents read from an open file descriptor to the hash. // diff --git a/src/ccache/inodecache.cpp b/src/ccache/inodecache.cpp index 21c92575..d2309f81 100644 --- a/src/ccache/inodecache.cpp +++ b/src/ccache/inodecache.cpp @@ -254,13 +254,13 @@ struct InodeCache::SharedRegion }; bool -InodeCache::mmap_file(const std::string& inode_cache_file) +InodeCache::mmap_file(const std::filesystem::path& path) { m_sr = nullptr; m_map.unmap(); - m_fd = util::Fd(open(inode_cache_file.c_str(), O_RDWR)); + m_fd = util::Fd(open(util::pstr(path).c_str(), O_RDWR)); if (!m_fd) { - LOG("Failed to open inode cache {}: {}", inode_cache_file, strerror(errno)); + LOG("Failed to open inode cache {}: {}", path, strerror(errno)); return false; } if (!fd_is_on_known_to_work_file_system(*m_fd)) { @@ -269,7 +269,7 @@ InodeCache::mmap_file(const std::string& inode_cache_file) auto map = util::MemoryMap::map(*m_fd, sizeof(SharedRegion)); if (!map) { - LOG("Failed to map inode cache file {}: {}", inode_cache_file, map.error()); + LOG("Failed to map inode cache file {}: {}", path, map.error()); return false; } @@ -285,13 +285,13 @@ InodeCache::mmap_file(const std::string& inode_cache_file) k_version); map->unmap(); m_fd.close(); - unlink(inode_cache_file.c_str()); + fs::remove(path); return false; } m_map = std::move(*map); m_sr = sr; if (m_config.debug()) { - LOG("Inode cache file loaded: {}", inode_cache_file); + LOG("Inode cache file loaded: {}", path); } return true; } @@ -368,11 +368,11 @@ InodeCache::with_bucket(const Hash::Digest& key_digest, } bool -InodeCache::create_new_file(const std::string& filename) +InodeCache::create_new_file(const fs::path& path) { // Create the new file to a temporary name to prevent other processes from // mapping it before it is fully initialized. - auto tmp_file = util::TemporaryFile::create(filename); + auto tmp_file = util::TemporaryFile::create(path); if (!tmp_file) { LOG("Failed to created inode cache file: {}", tmp_file.error()); return false; @@ -416,19 +416,19 @@ InodeCache::create_new_file(const std::string& filename) // simultaneously. Thus close the current file handle and reopen a new one, // which will make us use the first created file even if we didn't win the // race. - if (link(tmp_file->path.c_str(), filename.c_str()) != 0) { - LOG("Failed to link new inode cache: {}", strerror(errno)); + if (auto result = fs::create_hard_link(tmp_file->path, path); !result) { + LOG("Failed to link new inode cache: {}", result.error()); return false; } #else - if (MoveFileA(util::PathString(tmp_file->path).c_str(), filename.c_str()) + if (MoveFileA(util::pstr(tmp_file->path).c_str(), util::pstr(path).c_str()) == 0) { unsigned error = GetLastError(); if (error == ERROR_FILE_EXISTS) { // Not an error, another process won the race. Remove the file we just // created. - DeleteFileA(util::PathString(tmp_file->path).c_str()); - LOG("Another process created inode cache {}", filename); + DeleteFileA(util::pstr(tmp_file->path).c_str()); + LOG("Another process created inode cache {}", path); return true; } else { LOG("Failed to move new inode cache: {}", error); @@ -437,7 +437,7 @@ InodeCache::create_new_file(const std::string& filename) } #endif - LOG("Created a new inode cache {}", filename); + LOG("Created a new inode cache {}", path); return true; } @@ -486,19 +486,19 @@ InodeCache::initialize() return true; } - std::string filename = get_file(); - if (m_sr || mmap_file(filename)) { + fs::path path = get_path(); + if (m_sr || mmap_file(path)) { return true; } // Try to create a new cache if we failed to map an existing file. - create_new_file(filename); + create_new_file(path); // Concurrent processes could try to create new files simultaneously and the // file that actually landed on disk will be from the process that won the // race. Thus we try to open the file from disk instead of reusing the file // handle to the file we just created. - if (mmap_file(filename)) { + if (mmap_file(path)) { return true; } @@ -622,20 +622,20 @@ InodeCache::drop() m_sr = nullptr; m_map.unmap(); m_fd.close(); - std::string file = get_file(); - if (unlink(file.c_str()) != 0 && errno != ENOENT) { + fs::path path = get_path(); + if (!fs::remove(path)) { return false; } - LOG("Dropped inode cache {}", file); + LOG("Dropped inode cache {}", path); return true; } -std::string -InodeCache::get_file() +fs::path +InodeCache::get_path() { const uint8_t arch_bits = 8 * sizeof(void*); - return FMT( - "{}/inode-cache-{}.v{}", m_config.temporary_dir(), arch_bits, k_version); + return m_config.temporary_dir() + / FMT("inode-cache-{}.v{}", arch_bits, k_version); } int64_t diff --git a/src/ccache/inodecache.hpp b/src/ccache/inodecache.hpp index d2a05b72..0aee5f9b 100644 --- a/src/ccache/inodecache.hpp +++ b/src/ccache/inodecache.hpp @@ -97,7 +97,7 @@ public: bool drop(); // Returns name of the persistent file. - std::string get_file(); + std::filesystem::path get_path(); // Returns total number of cache hits. // @@ -124,7 +124,7 @@ private: struct SharedRegion; using BucketHandler = std::function; - bool mmap_file(const std::string& inode_cache_file); + bool mmap_file(const std::filesystem::path& path); bool hash_inode(const std::filesystem::path& path, ContentType type, @@ -133,7 +133,7 @@ private: bool with_bucket(const Hash::Digest& key_digest, const BucketHandler& bucket_handler); - static bool create_new_file(const std::string& filename); + static bool create_new_file(const std::filesystem::path& path); bool initialize(); diff --git a/src/ccache/storage/local/localstorage.cpp b/src/ccache/storage/local/localstorage.cpp index 039fd115..ec59f5d5 100644 --- a/src/ccache/storage/local/localstorage.cpp +++ b/src/ccache/storage/local/localstorage.cpp @@ -317,7 +317,7 @@ ratio(T numerator, T denominator) static CleanDirResult clean_dir( - const std::string& l2_dir, + const fs::path& l2_dir, const uint64_t max_size, const uint64_t max_files, const std::optional max_age = std::nullopt, @@ -333,7 +333,7 @@ clean_dir( uint64_t files_in_cache = 0; auto current_time = util::TimePoint::now(); std::unordered_map /*associated_raw_files*/> + std::vector /*associated_raw_files*/> raw_files_map; for (size_t i = 0; i < files.size(); @@ -354,9 +354,9 @@ clean_dir( if (namespace_ && file_type_from_path(file.path()) == FileType::raw) { util::PathString path_str(file.path()); - const auto result_filename = + const std::string result_path = FMT("{}R", path_str.str().substr(0, path_str.str().length() - 2)); - raw_files_map[result_filename].push_back(util::pstr(file.path())); + raw_files_map[result_path].push_back(file.path()); } cache_size += file.size_on_disk(); @@ -432,7 +432,7 @@ clean_dir( FileType file_type_from_path(const fs::path& path) { - std::string filename = util::pstr(path.filename()); + std::string filename = path.filename().string(); if (util::ends_with(filename, "M")) { return FileType::manifest; } else if (util::ends_with(filename, "R")) { @@ -616,8 +616,8 @@ LocalStorage::remove(const Hash::Digest& key, const core::CacheEntryType type) key, -1, -static_cast(cache_file.dir_entry.size_on_disk() / 1024)); } -std::string -LocalStorage::get_raw_file_path(std::string_view result_path, +fs::path +LocalStorage::get_raw_file_path(const fs::path& result_path, uint8_t file_number) { if (file_number >= 10) { @@ -627,11 +627,12 @@ LocalStorage::get_raw_file_path(std::string_view result_path, throw core::Error(FMT("Too high raw file entry number: {}", file_number)); } - const auto prefix = result_path.substr(0, result_path.length() - 1); - return FMT("{}{}W", prefix, file_number); + std::string s = result_path.string(); + s.pop_back(); + return FMT("{}{}W", s, file_number); } -std::string +fs::path LocalStorage::get_raw_file_path(const Hash::Digest& result_key, uint8_t file_number) const { @@ -646,7 +647,7 @@ LocalStorage::put_raw_files( const std::vector& raw_files) { const auto cache_file = look_up_cache_file(key, core::CacheEntryType::result); - core::ensure_dir_exists(fs::path(cache_file.path).parent_path()); + core::ensure_dir_exists(cache_file.path.parent_path()); int64_t files_change = 0; int64_t size_kibibyte_change = 0; @@ -750,7 +751,7 @@ LocalStorage::zero_all_statistics() const auto zeroable_fields = core::Statistics::get_zeroable_fields(); for_each_level_1_and_2_stats_file( - util::pstr(m_config.cache_dir()), [=](const std::string& path) { + m_config.cache_dir(), [=](const fs::path& path) { StatsFile(path).update([=](auto& cs) { for (const auto statistic : zeroable_fields) { cs.set(statistic, 0); @@ -770,7 +771,7 @@ LocalStorage::get_all_statistics() const // Add up the stats in each directory. for_each_level_1_and_2_stats_file( - util::pstr(m_config.cache_dir()), [&](const auto& path) { + m_config.cache_dir(), [&](const auto& path) { counters.set(Statistic::stats_zeroed_timestamp, 0); // Don't add counters.increment(StatsFile(path).read()); zero_timestamp = std::max(counters.get(Statistic::stats_zeroed_timestamp), @@ -932,7 +933,8 @@ LocalStorage::recompress(const std::optional level, l2_progress_receiver(0.1 + 0.9 * ratio(i, files.size())); } - if (util::ends_with(l2_dir, "f/f")) { + if (l2_dir.filename() == "f" + && l2_dir.parent_path().filename() == "f") { // Wait here instead of after for_each_cache_subdir to avoid // updating the progress bar to 100% before all work is done. thread_pool.shut_down(); @@ -1019,16 +1021,16 @@ LocalStorage::recompress(const std::optional level, // Private methods -std::string +fs::path LocalStorage::get_subdir(uint8_t l1_index) const { - return FMT("{}/{:x}", m_config.cache_dir(), l1_index); + return m_config.cache_dir() / FMT("{:x}", l1_index); } -std::string +fs::path LocalStorage::get_subdir(uint8_t l1_index, uint8_t l2_index) const { - return FMT("{}/{:x}/{:x}", m_config.cache_dir(), l1_index, l2_index); + return m_config.cache_dir() / FMT("{:x}/{:x}", l1_index, l2_index); } LocalStorage::LookUpCacheFileResult @@ -1069,14 +1071,14 @@ void LocalStorage::move_to_wanted_cache_level(const StatisticsCounters& counters, const Hash::Digest& key, core::CacheEntryType type, - const std::string& cache_file_path) + const fs::path& cache_file_path) { const auto wanted_level = calculate_wanted_cache_level(counters.get(Statistic::files_in_cache)); const auto wanted_path = get_path_in_cache( wanted_level, util::format_digest(key) + suffix_from_type(type)); if (cache_file_path != wanted_path) { - core::ensure_dir_exists(fs::path(wanted_path).parent_path()); + core::ensure_dir_exists(wanted_path.parent_path()); // Note: Two ccache processes may move the file at the same time, so failure // to rename is OK. @@ -1084,9 +1086,7 @@ LocalStorage::move_to_wanted_cache_level(const StatisticsCounters& counters, fs::rename(cache_file_path, wanted_path); for (const auto& raw_file : m_added_raw_files) { fs::rename(raw_file, - FMT("{}/{}", - fs::path(wanted_path).parent_path(), - fs::path(raw_file).filename())); + FMT("{}/{}", wanted_path.parent_path(), raw_file.filename())); } } } @@ -1477,7 +1477,7 @@ LocalStorage::clean_internal_tempdir() util::write_file(cleaned_stamp, ""); } -std::string +fs::path LocalStorage::get_path_in_cache(const uint8_t level, const std::string_view name) const { @@ -1492,11 +1492,11 @@ LocalStorage::get_path_in_cache(const uint8_t level, return (path / fs::path(name.substr(level))).string(); } -std::string +fs::path LocalStorage::get_lock_path(const std::string& name) const { - auto path = FMT("{}/lock/{}", m_config.cache_dir(), name); - core::ensure_dir_exists(fs::path(path).parent_path()); + auto path = m_config.cache_dir() / "lock" / name; + core::ensure_dir_exists(path.parent_path()); return path; } diff --git a/src/ccache/storage/local/localstorage.hpp b/src/ccache/storage/local/localstorage.hpp index 71b17912..55822727 100644 --- a/src/ccache/storage/local/localstorage.hpp +++ b/src/ccache/storage/local/localstorage.hpp @@ -80,10 +80,11 @@ public: void remove(const Hash::Digest& key, core::CacheEntryType type); - static std::string get_raw_file_path(std::string_view result_path, - uint8_t file_number); - std::string get_raw_file_path(const Hash::Digest& result_key, - uint8_t file_number) const; + static std::filesystem::path + get_raw_file_path(const std::filesystem::path& result_path, + uint8_t file_number); + std::filesystem::path get_raw_file_path(const Hash::Digest& result_key, + uint8_t file_number) const; void put_raw_files( const Hash::Digest& key, @@ -137,12 +138,12 @@ private: // a statistics file in the finalize method. core::StatisticsCounters m_counter_updates; - std::vector m_added_raw_files; + std::vector m_added_raw_files; bool m_stored_data = false; struct LookUpCacheFileResult { - std::string path; + std::filesystem::path path; util::DirEntry dir_entry; uint8_t level; }; @@ -150,8 +151,8 @@ private: LookUpCacheFileResult look_up_cache_file(const Hash::Digest& key, core::CacheEntryType type) const; - std::string get_subdir(uint8_t l1_index) const; - std::string get_subdir(uint8_t l1_index, uint8_t l2_index) const; + std::filesystem::path get_subdir(uint8_t l1_index) const; + std::filesystem::path get_subdir(uint8_t l1_index, uint8_t l2_index) const; StatsFile get_stats_file(uint8_t l1_index) const; StatsFile get_stats_file(uint8_t l1_index, uint8_t l2_index) const; @@ -159,7 +160,7 @@ private: void move_to_wanted_cache_level(const core::StatisticsCounters& counters, const Hash::Digest& key, core::CacheEntryType type, - const std::string& cache_file_path); + const std::filesystem::path& cache_file_path); void recount_level_1_dir(util::LongLivedLockFileManager& lock_manager, uint8_t l1_index); @@ -180,7 +181,7 @@ private: struct EvaluateCleanupResult { uint8_t l1_index; - std::string l1_path; + std::filesystem::path l1_path; core::StatisticsCounters l1_counters; uint64_t total_files; }; @@ -195,9 +196,10 @@ private: // Join the cache directory, a '/' and `name` into a single path and return // it. Additionally, `level` single-character, '/'-separated subpaths are // split from the beginning of `name` before joining them all. - std::string get_path_in_cache(uint8_t level, std::string_view name) const; + std::filesystem::path get_path_in_cache(uint8_t level, + std::string_view name) const; - std::string get_lock_path(const std::string& name) const; + std::filesystem::path get_lock_path(const std::string& name) const; util::LockFile get_auto_cleanup_lock() const; diff --git a/src/ccache/storage/local/statsfile.cpp b/src/ccache/storage/local/statsfile.cpp index c60869df..9ce023fd 100644 --- a/src/ccache/storage/local/statsfile.cpp +++ b/src/ccache/storage/local/statsfile.cpp @@ -21,13 +21,16 @@ #include #include #include +#include #include #include #include +namespace fs = util::filesystem; + namespace storage::local { -StatsFile::StatsFile(const std::string& path) : m_path(path) +StatsFile::StatsFile(const fs::path& path) : m_path(path) { } diff --git a/src/ccache/storage/local/statsfile.hpp b/src/ccache/storage/local/statsfile.hpp index 36df4b84..07d4ef47 100644 --- a/src/ccache/storage/local/statsfile.hpp +++ b/src/ccache/storage/local/statsfile.hpp @@ -20,16 +20,16 @@ #include +#include #include #include -#include namespace storage::local { class StatsFile { public: - explicit StatsFile(const std::string& path); + explicit StatsFile(const std::filesystem::path& path); // Read counters. No lock is acquired. If the file doesn't exist all returned // counters will be zero. @@ -45,7 +45,7 @@ public: OnlyIfChanged only_if_changed = OnlyIfChanged::no) const; private: - std::string m_path; + std::filesystem::path m_path; }; } // namespace storage::local diff --git a/src/ccache/storage/local/util.cpp b/src/ccache/storage/local/util.cpp index da14b3d2..0d23b3f0 100644 --- a/src/ccache/storage/local/util.cpp +++ b/src/ccache/storage/local/util.cpp @@ -21,10 +21,13 @@ #include #include #include +#include #include #include #include +namespace fs = util::filesystem; + using util::DirEntry; namespace storage::local { @@ -53,8 +56,8 @@ for_each_cache_subdir(const ProgressReceiver& progress_receiver, void for_each_level_1_and_2_stats_file( - const std::string& cache_dir, - const std::function function) + const fs::path& cache_dir, + const std::function function) { for (size_t level_1 = 0; level_1 <= 0xF; ++level_1) { function(FMT("{}/{:x}/stats", cache_dir, level_1)); @@ -65,7 +68,7 @@ for_each_level_1_and_2_stats_file( } std::vector -get_cache_dir_files(const std::string& dir) +get_cache_dir_files(const fs::path& dir) { std::vector files; diff --git a/src/ccache/storage/local/util.hpp b/src/ccache/storage/local/util.hpp index 317c7be1..b006c360 100644 --- a/src/ccache/storage/local/util.hpp +++ b/src/ccache/storage/local/util.hpp @@ -20,8 +20,8 @@ #include +#include #include -#include #include namespace storage::local { @@ -37,8 +37,8 @@ void for_each_cache_subdir(const ProgressReceiver& progress_receiver, const SubdirProgressVisitor& visitor); void for_each_level_1_and_2_stats_file( - const std::string& cache_dir, - const std::function function); + const std::filesystem::path& cache_dir, + const std::function function); // Get a list of files in a subdirectory of the cache. // @@ -50,6 +50,7 @@ void for_each_level_1_and_2_stats_file( // - CACHEDIR.TAG // - stats // - .nfs* (temporary NFS files that may be left for open but deleted files). -std::vector get_cache_dir_files(const std::string& dir); +std::vector +get_cache_dir_files(const std::filesystem::path& dir); } // namespace storage::local diff --git a/src/ccache/util/logging.cpp b/src/ccache/util/logging.cpp index 2115dfea..178dbd06 100644 --- a/src/ccache/util/logging.cpp +++ b/src/ccache/util/logging.cpp @@ -174,7 +174,7 @@ bulk_log(std::string_view message) } void -dump_log(const std::string& path) +dump_log(const fs::path& path) { if (!enabled()) { return; diff --git a/src/ccache/util/logging.hpp b/src/ccache/util/logging.hpp index 1919f0ca..1628759d 100644 --- a/src/ccache/util/logging.hpp +++ b/src/ccache/util/logging.hpp @@ -64,6 +64,6 @@ void log(std::string_view message); void bulk_log(std::string_view message); // Write the current log memory buffer to `path`. -void dump_log(const std::string& path); +void dump_log(const std::filesystem::path& path); } // namespace util::logging diff --git a/unittest/test_inodecache.cpp b/unittest/test_inodecache.cpp index 878f083e..79b45927 100644 --- a/unittest/test_inodecache.cpp +++ b/unittest/test_inodecache.cpp @@ -172,9 +172,9 @@ TEST_CASE("Drop file") InodeCache inode_cache(config, util::Duration(0)); inode_cache.get("a", InodeCache::ContentType::raw); - CHECK(util::DirEntry(inode_cache.get_file())); + CHECK(util::DirEntry(inode_cache.get_path())); CHECK(inode_cache.drop()); - CHECK(!util::DirEntry(inode_cache.get_file())); + CHECK(!util::DirEntry(inode_cache.get_path())); CHECK(inode_cache.drop()); }