[PATCH] D50521: [Support] NFC: Allow modifying access/modification times independently in sys::fs::setLastModificationAndAccessTime.
Jordan Rupprecht via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 13 16:04:36 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rL339628: [Support] NFC: Allow modifying access/modification times independently in sys… (authored by rupprecht, committed by ).
Repository:
rL LLVM
https://reviews.llvm.org/D50521
Files:
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
Index: llvm/trunk/lib/Support/Windows/Path.inc
===================================================================
--- llvm/trunk/lib/Support/Windows/Path.inc
+++ llvm/trunk/lib/Support/Windows/Path.inc
@@ -766,10 +766,12 @@
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();
}
Index: llvm/trunk/lib/Support/Unix/Path.inc
===================================================================
--- llvm/trunk/lib/Support/Unix/Path.inc
+++ llvm/trunk/lib/Support/Unix/Path.inc
@@ -583,17 +583,22 @@
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();
Index: llvm/trunk/unittests/Support/Path.cpp
===================================================================
--- llvm/trunk/unittests/Support/Path.cpp
+++ llvm/trunk/unittests/Support/Path.cpp
@@ -1297,7 +1297,7 @@
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.
Index: llvm/trunk/tools/llvm-ar/llvm-ar.cpp
===================================================================
--- llvm/trunk/tools/llvm-ar/llvm-ar.cpp
+++ llvm/trunk/tools/llvm-ar/llvm-ar.cpp
@@ -410,7 +410,7 @@
auto ModTimeOrErr = C.getLastModified();
failIfError(ModTimeOrErr.takeError());
failIfError(
- sys::fs::setLastModificationAndAccessTime(FD, ModTimeOrErr.get()));
+ sys::fs::setLastAccessAndModificationTime(FD, ModTimeOrErr.get()));
}
if (close(FD))
Index: llvm/trunk/include/llvm/Support/FileSystem.h
===================================================================
--- llvm/trunk/include/llvm/Support/FileSystem.h
+++ llvm/trunk/include/llvm/Support/FileSystem.h
@@ -666,7 +666,15 @@
/// @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?
///
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50521.160478.patch
Type: text/x-patch
Size: 4422 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180813/67856e37/attachment.bin>
More information about the llvm-commits
mailing list