[llvm] r339628 - [Support] NFC: Allow modifying access/modification times independently in sys::fs::setLastModificationAndAccessTime.
Jordan Rupprecht via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 13 16:03:45 PDT 2018
Author: rupprecht
Date: Mon Aug 13 16:03:45 2018
New Revision: 339628
URL: http://llvm.org/viewvc/llvm-project?rev=339628&view=rev
Log:
[Support] NFC: Allow modifying access/modification times independently in sys::fs::setLastModificationAndAccessTime.
Summary:
Add an overload to sys::fs::setLastModificationAndAccessTime that allows setting last access and modification times separately. This will allow tools to use this API when they want to preserve both the access and modification times from an input file, which may be different.
Also note that both the POSIX (futimens/futimes) and Windows (SetFileTime) APIs take the two timestamps in the order of (1) access (2) modification time, so this renames the method to "setLastAccessAndModificationTime" to make it clear which timestamp is which.
For existing callers, the 1-arg overload just sets both timestamps to the same thing.
Subscribers: llvm-commits
Differential Revision: https://reviews.llvm.org/D50521
Modified:
llvm/trunk/include/llvm/Support/FileSystem.h
llvm/trunk/lib/Support/Unix/Path.inc
llvm/trunk/lib/Support/Windows/Path.inc
llvm/trunk/tools/llvm-ar/llvm-ar.cpp
llvm/trunk/unittests/Support/Path.cpp
Modified: llvm/trunk/include/llvm/Support/FileSystem.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FileSystem.h?rev=339628&r1=339627&r2=339628&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/FileSystem.h (original)
+++ llvm/trunk/include/llvm/Support/FileSystem.h Mon Aug 13 16:03:45 2018
@@ -666,7 +666,15 @@ inline std::error_code file_size(const T
/// @returns errc::success if the file times were successfully set, otherwise a
/// platform-specific error_code or errc::function_not_supported on
/// platforms where the functionality isn't available.
-std::error_code setLastModificationAndAccessTime(int FD, TimePoint<> Time);
+std::error_code setLastAccessAndModificationTime(int FD, TimePoint<> AccessTime,
+ TimePoint<> ModificationTime);
+
+/// Simpler version that sets both file modification and access time to the same
+/// time.
+inline std::error_code setLastAccessAndModificationTime(int FD,
+ TimePoint<> Time) {
+ return setLastAccessAndModificationTime(FD, Time, Time);
+}
/// Is status available?
///
Modified: llvm/trunk/lib/Support/Unix/Path.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/Path.inc?rev=339628&r1=339627&r2=339628&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Unix/Path.inc (original)
+++ llvm/trunk/lib/Support/Unix/Path.inc Mon Aug 13 16:03:45 2018
@@ -583,17 +583,22 @@ std::error_code setPermissions(const Twi
return std::error_code();
}
-std::error_code setLastModificationAndAccessTime(int FD, TimePoint<> Time) {
+std::error_code setLastAccessAndModificationTime(int FD, TimePoint<> AccessTime,
+ TimePoint<> ModificationTime) {
#if defined(HAVE_FUTIMENS)
timespec Times[2];
- Times[0] = Times[1] = sys::toTimeSpec(Time);
+ Times[0] = sys::toTimeSpec(AccessTime);
+ Times[1] = sys::toTimeSpec(ModificationTime);
if (::futimens(FD, Times))
return std::error_code(errno, std::generic_category());
return std::error_code();
#elif defined(HAVE_FUTIMES)
timeval Times[2];
- Times[0] = Times[1] = sys::toTimeVal(
- std::chrono::time_point_cast<std::chrono::microseconds>(Time));
+ Times[0] = sys::toTimeVal(
+ std::chrono::time_point_cast<std::chrono::microseconds>(AccessTime));
+ Times[1] =
+ sys::toTimeVal(std::chrono::time_point_cast<std::chrono::microseconds>(
+ ModificationTime));
if (::futimes(FD, Times))
return std::error_code(errno, std::generic_category());
return std::error_code();
Modified: llvm/trunk/lib/Support/Windows/Path.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Path.inc?rev=339628&r1=339627&r2=339628&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/Path.inc (original)
+++ llvm/trunk/lib/Support/Windows/Path.inc Mon Aug 13 16:03:45 2018
@@ -766,10 +766,12 @@ std::error_code setPermissions(const Twi
return std::error_code();
}
-std::error_code setLastModificationAndAccessTime(int FD, TimePoint<> Time) {
- FILETIME FT = toFILETIME(Time);
+std::error_code setLastAccessAndModificationTime(int FD, TimePoint<> AccessTime,
+ TimePoint<> ModificationTime) {
+ FILETIME AccessFT = toFILETIME(AccessTime);
+ FILETIME ModifyFT = toFILETIME(ModificationTime);
HANDLE FileHandle = reinterpret_cast<HANDLE>(_get_osfhandle(FD));
- if (!SetFileTime(FileHandle, NULL, &FT, &FT))
+ if (!SetFileTime(FileHandle, NULL, &AccessFT, &ModifyFT))
return mapWindowsError(::GetLastError());
return std::error_code();
}
Modified: llvm/trunk/tools/llvm-ar/llvm-ar.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ar/llvm-ar.cpp?rev=339628&r1=339627&r2=339628&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-ar/llvm-ar.cpp (original)
+++ llvm/trunk/tools/llvm-ar/llvm-ar.cpp Mon Aug 13 16:03:45 2018
@@ -410,7 +410,7 @@ static void doExtract(StringRef Name, co
auto ModTimeOrErr = C.getLastModified();
failIfError(ModTimeOrErr.takeError());
failIfError(
- sys::fs::setLastModificationAndAccessTime(FD, ModTimeOrErr.get()));
+ sys::fs::setLastAccessAndModificationTime(FD, ModTimeOrErr.get()));
}
if (close(FD))
Modified: llvm/trunk/unittests/Support/Path.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/Path.cpp?rev=339628&r1=339627&r2=339628&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/Path.cpp (original)
+++ llvm/trunk/unittests/Support/Path.cpp Mon Aug 13 16:03:45 2018
@@ -1297,7 +1297,7 @@ TEST_F(FileSystemTest, OpenFileForRead)
ASSERT_NO_ERROR(sys::fs::openFileForWrite(Twine(TempPath), FileDescriptor,
fs::CD_OpenExisting));
TimePoint<> Epoch(std::chrono::milliseconds(0));
- ASSERT_NO_ERROR(fs::setLastModificationAndAccessTime(FileDescriptor, Epoch));
+ ASSERT_NO_ERROR(fs::setLastAccessAndModificationTime(FileDescriptor, Epoch));
::close(FileDescriptor);
// Open the file and ensure access time is updated, when forced.
More information about the llvm-commits
mailing list