[Lldb-commits] [lldb] r364457 - [Reproducers] Copy over access/modification time in the FileCollector.

Jonas Devlieghere via lldb-commits lldb-commits at lists.llvm.org
Wed Jun 26 11:14:31 PDT 2019


Author: jdevlieghere
Date: Wed Jun 26 11:14:31 2019
New Revision: 364457

URL: http://llvm.org/viewvc/llvm-project?rev=364457&view=rev
Log:
[Reproducers] Copy over access/modification time in the FileCollector.

Copy over access and modification time for the files included in the
reproducer. This is needed to pass tests that check the integrity of
object files based on their time stamp.

Modified:
    lldb/trunk/source/Utility/FileCollector.cpp

Modified: lldb/trunk/source/Utility/FileCollector.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Utility/FileCollector.cpp?rev=364457&r1=364456&r2=364457&view=diff
==============================================================================
--- lldb/trunk/source/Utility/FileCollector.cpp (original)
+++ lldb/trunk/source/Utility/FileCollector.cpp Wed Jun 26 11:14:31 2019
@@ -11,6 +11,7 @@
 #include "llvm/ADT/SmallString.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/Path.h"
+#include "llvm/Support/Process.h"
 
 using namespace lldb_private;
 using namespace llvm;
@@ -104,6 +105,27 @@ void FileCollector::AddFileImpl(StringRe
   AddFileToMapping(virtual_path, dst_path);
 }
 
+/// Set the access and modification time for the given file from the given
+/// status object.
+static std::error_code
+CopyAccessAndModificationTime(StringRef filename,
+                              const sys::fs::file_status &stat) {
+  int fd;
+
+  if (auto ec =
+          sys::fs::openFileForWrite(filename, fd, sys::fs::CD_OpenExisting))
+    return ec;
+
+  if (auto ec = sys::fs::setLastAccessAndModificationTime(
+          fd, stat.getLastAccessedTime(), stat.getLastModificationTime()))
+    return ec;
+
+  if (auto ec = sys::Process::SafelyCloseFileDescriptor(fd))
+    return ec;
+
+  return {};
+}
+
 std::error_code FileCollector::CopyFiles(bool stop_on_error) {
   for (auto &entry : m_vfs_writer.getMappings()) {
     // Create directory tree.
@@ -127,6 +149,15 @@ std::error_code FileCollector::CopyFiles
           return ec;
       }
     }
+
+    // Copy over modification time.
+    sys::fs::file_status stat;
+    if (std::error_code ec = sys::fs::status(entry.VPath, stat)) {
+      if (stop_on_error)
+        return ec;
+      continue;
+    }
+    CopyAccessAndModificationTime(entry.RPath, stat);
   }
   return {};
 }




More information about the lldb-commits mailing list