From dbe5c17a9610cecb2dcab311a4b9844bfe94cf83 Mon Sep 17 00:00:00 2001 From: gabime Date: Fri, 25 Oct 2019 15:56:23 +0300 Subject: [PATCH] Renamed file_exists()->path_exists() --- include/spdlog/details/file_helper-inl.h | 5 ----- include/spdlog/details/file_helper.h | 1 - include/spdlog/details/os-inl.h | 10 +++++----- include/spdlog/details/os.h | 2 +- include/spdlog/sinks/rotating_file_sink-inl.h | 3 ++- tests/test_create_dir.cpp | 4 ++-- tests/test_file_helper.cpp | 8 -------- 7 files changed, 10 insertions(+), 23 deletions(-) diff --git a/include/spdlog/details/file_helper-inl.h b/include/spdlog/details/file_helper-inl.h index cd6b5480..98ef82fa 100644 --- a/include/spdlog/details/file_helper-inl.h +++ b/include/spdlog/details/file_helper-inl.h @@ -97,11 +97,6 @@ SPDLOG_INLINE const filename_t &file_helper::filename() const return _filename; } -SPDLOG_INLINE bool file_helper::file_exists(const filename_t &fname) -{ - return os::file_exists(fname); -} - // // return file path and its extension: // diff --git a/include/spdlog/details/file_helper.h b/include/spdlog/details/file_helper.h index 990d99e3..89d6b244 100644 --- a/include/spdlog/details/file_helper.h +++ b/include/spdlog/details/file_helper.h @@ -29,7 +29,6 @@ public: void write(const memory_buf_t &buf); size_t size() const; const filename_t &filename() const; - static bool file_exists(const filename_t &fname); // // return file path and its extension: diff --git a/include/spdlog/details/os-inl.h b/include/spdlog/details/os-inl.h index 31b20cea..b5669ac7 100644 --- a/include/spdlog/details/os-inl.h +++ b/include/spdlog/details/os-inl.h @@ -178,7 +178,7 @@ SPDLOG_INLINE int remove(const filename_t &filename) SPDLOG_NOEXCEPT SPDLOG_INLINE int remove_if_exists(const filename_t &filename) SPDLOG_NOEXCEPT { - return file_exists(filename) ? remove(filename) : 0; + return path_exists(filename) ? remove(filename) : 0; } SPDLOG_INLINE int rename(const filename_t &filename1, const filename_t &filename2) SPDLOG_NOEXCEPT @@ -190,8 +190,8 @@ SPDLOG_INLINE int rename(const filename_t &filename1, const filename_t &filename #endif } -// Return true if file exists -SPDLOG_INLINE bool file_exists(const filename_t &filename) SPDLOG_NOEXCEPT +// Return true if path exists (file or directory) +SPDLOG_INLINE bool path_exists(const filename_t &filename) SPDLOG_NOEXCEPT { #ifdef _WIN32 #ifdef SPDLOG_WCHAR_FILENAMES @@ -481,7 +481,7 @@ SPDLOG_INLINE bool mkdir_(const filename_t &path) // return true on success SPDLOG_INLINE bool create_dir(filename_t path) { - if (file_exists(path)) + if (path_exists(path)) { return true; } @@ -503,7 +503,7 @@ SPDLOG_INLINE bool create_dir(filename_t path) auto subdir = path.substr(0, token_pos); - if (!subdir.empty() && !file_exists(subdir) && !mkdir_(subdir)) + if (!subdir.empty() && !path_exists(subdir) && !mkdir_(subdir)) { return false; // return error if failed creating dir } diff --git a/include/spdlog/details/os.h b/include/spdlog/details/os.h index 2ab828ba..e275a40f 100644 --- a/include/spdlog/details/os.h +++ b/include/spdlog/details/os.h @@ -53,7 +53,7 @@ int remove_if_exists(const filename_t &filename) SPDLOG_NOEXCEPT; int rename(const filename_t &filename1, const filename_t &filename2) SPDLOG_NOEXCEPT; // Return if file exists. -bool file_exists(const filename_t &filename) SPDLOG_NOEXCEPT; +bool path_exists(const filename_t &filename) SPDLOG_NOEXCEPT; // Return file size according to open FILE* object size_t filesize(FILE *f); diff --git a/include/spdlog/sinks/rotating_file_sink-inl.h b/include/spdlog/sinks/rotating_file_sink-inl.h index 15443c5a..82347001 100644 --- a/include/spdlog/sinks/rotating_file_sink-inl.h +++ b/include/spdlog/sinks/rotating_file_sink-inl.h @@ -88,11 +88,12 @@ template SPDLOG_INLINE void rotating_file_sink::rotate_() { using details::os::filename_to_str; + using details::os::path_exists; file_helper_.close(); for (auto i = max_files_; i > 0; --i) { filename_t src = calc_filename(base_filename_, i - 1); - if (!details::file_helper::file_exists(src)) + if (!path_exists(src)) { continue; } diff --git a/tests/test_create_dir.cpp b/tests/test_create_dir.cpp index 3e428d74..a41c63a5 100644 --- a/tests/test_create_dir.cpp +++ b/tests/test_create_dir.cpp @@ -4,13 +4,13 @@ #include "includes.h" using spdlog::details::os::create_dir; -using spdlog::details::os::file_exists; +using spdlog::details::os::path_exists; bool try_create_dir(const char *path, const char *normalized_path) { auto rv = create_dir(path); REQUIRE(rv == true); - return file_exists(normalized_path); + return path_exists(normalized_path); } TEST_CASE("create_dir", "[create_dir]") diff --git a/tests/test_file_helper.cpp b/tests/test_file_helper.cpp index 85f62ae2..0aaa4ce6 100644 --- a/tests/test_file_helper.cpp +++ b/tests/test_file_helper.cpp @@ -38,14 +38,6 @@ TEST_CASE("file_helper_size", "[file_helper::size()]]") REQUIRE(get_filesize(target_filename) == expected_size); } -TEST_CASE("file_helper_exists", "[file_helper::file_exists()]]") -{ - prepare_logdir(); - REQUIRE(!file_helper::file_exists(target_filename)); - file_helper helper; - helper.open(target_filename); - REQUIRE(file_helper::file_exists(target_filename)); -} TEST_CASE("file_helper_reopen", "[file_helper::reopen()]]") {