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 diff --git a/include/ghc/filesystem.hpp b/include/ghc/filesystem.hpp index 9b138f9..9213f72 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -3431,6 +3431,9 @@ GHC_INLINE path path::lexically_relative(const path& base) const --count; } } + if (count == 0 && (a == end() || a->empty())) { + return path("."); + } if (count < 0) { return path(); } @@ -4099,7 +4102,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; } @@ -5818,7 +5821,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(); @@ -5845,7 +5848,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); diff --git a/test/filesystem_test.cpp b/test/filesystem_test.cpp index 4a06c23..0be179f 100644 --- a/test/filesystem_test.cpp +++ b/test/filesystem_test.cpp @@ -965,6 +965,10 @@ 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("/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") == ".");