diff --git a/README.md b/README.md index a2826be..393712f 100644 --- a/README.md +++ b/README.md @@ -665,6 +665,8 @@ to the expected behavior. now reports an error for non-regular sources. * Fix for [#206](https://github.com/gulrak/filesystem/issues/206), Windows error formatting now handles unknown error codes safely. +* Fix for [#207](https://github.com/gulrak/filesystem/issues/207), + `last_write_time()` now consistently follows symlinks. * Fix for [#185](https://github.com/gulrak/filesystem/issues/185), `lexically_normal()` now preserves unresolved parent components in relative paths. diff --git a/include/ghc/filesystem.hpp b/include/ghc/filesystem.hpp index a554f10..3334dd9 100644 --- a/include/ghc/filesystem.hpp +++ b/include/ghc/filesystem.hpp @@ -4713,9 +4713,9 @@ GHC_INLINE void last_write_time(const path& p, file_time_type new_time, std::err times[1].tv_sec = static_cast(std::chrono::duration_cast(d).count()); times[1].tv_nsec = static_cast(std::chrono::duration_cast(d).count() % 1000000000); #if defined(__ANDROID_API__) && __ANDROID_API__ < 12 - if (syscall(__NR_utimensat, AT_FDCWD, p.c_str(), times, AT_SYMLINK_NOFOLLOW) != 0) { + if (syscall(__NR_utimensat, AT_FDCWD, p.c_str(), times, 0) != 0) { #else - if (::utimensat((int)AT_FDCWD, p.c_str(), times, AT_SYMLINK_NOFOLLOW) != 0) { + if (::utimensat((int)AT_FDCWD, p.c_str(), times, 0) != 0) { #endif ec = detail::make_system_error(); } diff --git a/test/filesystem_test.cpp b/test/filesystem_test.cpp index fa3172e..50caacf 100644 --- a/test/filesystem_test.cpp +++ b/test/filesystem_test.cpp @@ -2568,6 +2568,24 @@ TEST_CASE("fs.op.last_write_time - last_write_time", "[filesystem][operations][f CHECK_NOTHROW(fs::last_write_time("foo", nt, ec)); CHECK(std::abs(std::chrono::duration_cast(fs::last_write_time("foo") - nt).count()) < 1); CHECK(!ec); + if (is_symlink_creation_supported()) { +#if !defined(GHC_OS_WINDOWS) && !defined(GHC_OS_WEB) + struct ::stat linkStatBefore; + REQUIRE(::lstat("foo2", &linkStatBefore) == 0); +#endif + nt = timeFromString("2015-10-21T04:28:00"); + CHECK_NOTHROW(fs::last_write_time("foo2", nt)); + CHECK(std::abs(std::chrono::duration_cast(fs::last_write_time("foo") - nt).count()) < 1); + nt = timeFromString("2015-10-21T04:27:00"); + CHECK_NOTHROW(fs::last_write_time("foo2", nt, ec)); + CHECK(!ec); + CHECK(std::abs(std::chrono::duration_cast(fs::last_write_time("foo") - nt).count()) < 1); +#if !defined(GHC_OS_WINDOWS) && !defined(GHC_OS_WEB) + struct ::stat linkStatAfter; + REQUIRE(::lstat("foo2", &linkStatAfter) == 0); + CHECK(linkStatAfter.st_mtime == linkStatBefore.st_mtime); +#endif + } CHECK_THROWS_AS(fs::last_write_time("bar", nt), fs::filesystem_error); CHECK_NOTHROW(fs::last_write_time("bar", nt, ec)); CHECK(ec);