From a0a7c1f552ab023bef738529c4d7ce2fc4e7a338 Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Thu, 26 Jul 2018 03:57:26 +0000 Subject: [PATCH] Cleanup the last_write_time internals llvm-svn: 338001 --- .../experimental/filesystem/filesystem_common.h | 40 +++++++++++++--------- libcxx/src/experimental/filesystem/operations.cpp | 3 +- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/libcxx/src/experimental/filesystem/filesystem_common.h b/libcxx/src/experimental/filesystem/filesystem_common.h index 5d2a5ed..94f4d41 100644 --- a/libcxx/src/experimental/filesystem/filesystem_common.h +++ b/libcxx/src/experimental/filesystem/filesystem_common.h @@ -19,6 +19,7 @@ #include #include #include +#include // for ::utimes as used in __last_write_time #include /* values for fchmodat */ #include @@ -33,14 +34,6 @@ #endif #endif -#if !defined(_LIBCPP_USE_UTIMENSAT) -#include // for ::utimes as used in __last_write_time -#endif - -#if !defined(UTIME_OMIT) -#include // for ::utimes as used in __last_write_time -#endif - #if defined(__GNUC__) #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wunused-function" @@ -389,9 +382,11 @@ TimeSpec extract_mtime(StatT const& st) { return st.st_mtim; } TimeSpec extract_atime(StatT const& st) { return st.st_atim; } #endif -bool set_file_times(const path& p, std::array const& TS, +// allow the utimes implementation to compile even it we're not going +// to use it. + +bool posix_utimes(const path& p, std::array const& TS, error_code& ec) { -#if !defined(_LIBCPP_USE_UTIMENSAT) using namespace chrono; auto Convert = [](long nsec) { using int_type = decltype(std::declval<::timeval>().tv_usec); @@ -400,22 +395,35 @@ bool set_file_times(const path& p, std::array const& TS, }; struct ::timeval ConvertedTS[2] = {{TS[0].tv_sec, Convert(TS[0].tv_nsec)}, {TS[1].tv_sec, Convert(TS[1].tv_nsec)}}; - if (::utimes(p.c_str(), ConvertedTS) == -1) -#else + if (::utimes(p.c_str(), ConvertedTS) == -1) { + ec = capture_errno(); + return true; + } + return false; +} + +#if defined(_LIBCPP_USE_UTIMENSAT) +bool posix_utimensat(const path& p, std::array const& TS, + error_code& ec) { if (::utimensat(AT_FDCWD, p.c_str(), TS.data(), 0) == -1) -#endif { ec = capture_errno(); return true; } return false; } +#endif -bool set_time_spec_to(TimeSpec& TS, file_time_type NewTime) { - return !fs_time::set_times_checked( - &TS.tv_sec, &TS.tv_nsec, NewTime); +bool set_file_times(const path& p, std::array const& TS, + error_code& ec) { +#if !defined(_LIBCPP_USE_UTIMENSAT) + return posix_utimes(p, TS, ec); +#else + return posix_utimensat(p, TS, ec); +#endif } + } // namespace } // end namespace detail diff --git a/libcxx/src/experimental/filesystem/operations.cpp b/libcxx/src/experimental/filesystem/operations.cpp index d570668..028d5bf 100644 --- a/libcxx/src/experimental/filesystem/operations.cpp +++ b/libcxx/src/experimental/filesystem/operations.cpp @@ -1017,6 +1017,7 @@ file_time_type __last_write_time(const path& p, error_code *ec) void __last_write_time(const path& p, file_time_type new_time, error_code *ec) { + using detail::fs_time; ErrorHandler err("last_write_time", ec, &p); error_code m_ec; @@ -1034,7 +1035,7 @@ void __last_write_time(const path& p, file_time_type new_time, tbuf[0].tv_sec = 0; tbuf[0].tv_nsec = UTIME_OMIT; #endif - if (detail::set_time_spec_to(tbuf[1], new_time)) + if (!fs_time::convert_to_timespec(tbuf[1], new_time)) return err.report(errc::value_too_large); detail::set_file_times(p, tbuf, m_ec); -- 2.7.4