From 0ef214a7a00d1bfd4cc65cc11f5248fed8d5515b Mon Sep 17 00:00:00 2001 From: Chris Sauer Date: Wed, 15 Nov 2023 14:18:03 -0800 Subject: [PATCH 1/4] Add reference to Bazel rules --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 5321132..f510042 100644 --- a/README.md +++ b/README.md @@ -397,6 +397,10 @@ The `CMakeLists.txt` offers a few options to customize its behavior: `CMAKE_CXX_COMPILE_FEATURES` when the detection of C++17 or C++20 for additional tests is not working (e.g. `cxx_std_20` to enforce building a `filesystem_test_cpp20` with C++20). +### Bazel + +Please use [hedronvision/bazel-cc-filesystem-backport](https://github.com/hedronvision/bazel-cc-filesystem-backport), which will automatically set everything up for you. + ### Versioning There is a version macro `GHC_FILESYSTEM_VERSION` defined in case future changes From fc19b58459cf89620bb274ff3548accaf525840b Mon Sep 17 00:00:00 2001 From: noexcept Date: Wed, 20 Dec 2023 11:56:57 +0000 Subject: [PATCH 2/4] fix infinite loop when errno is EINTR --- include/ghc/filesystem.hpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/include/ghc/filesystem.hpp b/include/ghc/filesystem.hpp index 86a6392..8aa4167 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -3974,7 +3974,7 @@ GHC_INLINE bool copy_file(const path& from, const path& to, copy_options options } ssize_t br, bw; while (true) { - do { br = ::read(in, buffer.data(), buffer.size()); } while(errno == EINTR); + do { br = ::read(in, buffer.data(), buffer.size()); } while(errno == EINTR && !br); if(!br) { break; } @@ -5693,7 +5693,7 @@ class directory_iterator::impl , _entry(nullptr) { if (!path.empty()) { - do { _dir = ::opendir(path.native().c_str()); } while(errno == EINTR); + do { _dir = ::opendir(path.native().c_str()); } while(errno == EINTR && !_dir); if (!_dir) { auto error = errno; _base = filesystem::path(); @@ -5720,7 +5720,7 @@ class directory_iterator::impl do { skip = false; errno = 0; - do { _entry = ::readdir(_dir); } while(errno == EINTR); + do { _entry = ::readdir(_dir); } while(errno == EINTR && !_entry); if (_entry) { _dir_entry._path = _base; _dir_entry._path.append_name(_entry->d_name); From 768b5cb11b39c54ae0cb97a4c9d1ba25dc1cdfd9 Mon Sep 17 00:00:00 2001 From: vgeorgiev Date: Wed, 21 Feb 2024 11:07:19 -0600 Subject: [PATCH 3/4] Fix lexically_relative return when base path evaluates to *this --- include/ghc/filesystem.hpp | 3 +++ test/filesystem_test.cpp | 3 +++ 2 files changed, 6 insertions(+) diff --git a/include/ghc/filesystem.hpp b/include/ghc/filesystem.hpp index 8aa4167..5384e7b 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -3306,6 +3306,9 @@ GHC_INLINE path path::lexically_relative(const path& base) const --count; } } + if (count == 0 && (a == end() || empty())) { + return path("."); + } if (count < 0) { return path(); } diff --git a/test/filesystem_test.cpp b/test/filesystem_test.cpp index 4a06c23..d8cc024 100644 --- a/test/filesystem_test.cpp +++ b/test/filesystem_test.cpp @@ -965,6 +965,9 @@ TEST_CASE("fs.path.gen - path generation", "[filesystem][path][fs.path.gen]") // lexically_relative() CHECK(fs::path("/a/d").lexically_relative("/a/b/c") == "../../d"); CHECK(fs::path("/a/b/c").lexically_relative("/a/d") == "../b/c"); + CHECK(fs::path("/a/b/c").lexically_relative("/a/b/c/d/..") == "."); + CHECK(fs::path("").lexically_relative("/a/..") == ""); + CHECK(fs::path("").lexically_relative("a/..") == "."); CHECK(fs::path("a/b/c").lexically_relative("a") == "b/c"); CHECK(fs::path("a/b/c").lexically_relative("a/b/c/x/y") == "../.."); CHECK(fs::path("a/b/c").lexically_relative("a/b/c") == "."); From eeed3142371745467d3ace3599db0744a86c53ad Mon Sep 17 00:00:00 2001 From: vgeorgiev Date: Wed, 21 Feb 2024 17:55:00 -0600 Subject: [PATCH 4/4] Fix handling of trailing slash --- include/ghc/filesystem.hpp | 2 +- test/filesystem_test.cpp | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/include/ghc/filesystem.hpp b/include/ghc/filesystem.hpp index 5384e7b..1770d73 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -3306,7 +3306,7 @@ GHC_INLINE path path::lexically_relative(const path& base) const --count; } } - if (count == 0 && (a == end() || empty())) { + if (count == 0 && (a == end() || a->empty())) { return path("."); } if (count < 0) { diff --git a/test/filesystem_test.cpp b/test/filesystem_test.cpp index d8cc024..0be179f 100644 --- a/test/filesystem_test.cpp +++ b/test/filesystem_test.cpp @@ -966,6 +966,7 @@ TEST_CASE("fs.path.gen - path generation", "[filesystem][path][fs.path.gen]") CHECK(fs::path("/a/d").lexically_relative("/a/b/c") == "../../d"); CHECK(fs::path("/a/b/c").lexically_relative("/a/d") == "../b/c"); CHECK(fs::path("/a/b/c").lexically_relative("/a/b/c/d/..") == "."); + CHECK(fs::path("/a/b/c/").lexically_relative("/a/b/c/d/..") == "."); CHECK(fs::path("").lexically_relative("/a/..") == ""); CHECK(fs::path("").lexically_relative("a/..") == "."); CHECK(fs::path("a/b/c").lexically_relative("a") == "b/c");