Add support for getting the last modification time from a file_status.
authorRafael Espindola <rafael.espindola@gmail.com>
Thu, 20 Jun 2013 18:42:04 +0000 (18:42 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Thu, 20 Jun 2013 18:42:04 +0000 (18:42 +0000)
Use that in llvm-ar.cpp to replace a use of sys::PathWithStatus.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184450 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/FileSystem.h
lib/Support/Unix/PathV2.inc
lib/Support/Windows/PathV2.inc
tools/llvm-ar/llvm-ar.cpp

index 6b3b126ea0326f871531c97550415a684fc39b61..c9ecc30efbf455f1ce02337fc31f151487dd5880 100644 (file)
@@ -33,6 +33,7 @@
 #include "llvm/ADT/Twine.h"
 #include "llvm/Support/DataTypes.h"
 #include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/TimeValue.h"
 #include "llvm/Support/system_error.h"
 #include <ctime>
 #include <iterator>
@@ -151,6 +152,7 @@ class file_status
   #if defined(LLVM_ON_UNIX)
   dev_t fs_st_dev;
   ino_t fs_st_ino;
+  time_t fs_st_mtime;
   #elif defined (LLVM_ON_WIN32)
   uint32_t LastWriteTimeHigh;
   uint32_t LastWriteTimeLow;
@@ -177,6 +179,7 @@ public:
   // setters
   void type(file_type v) { Type = v; }
   void permissions(perms p) { Perms = p; }
+  TimeValue getLastModificationTime();
 };
 
 /// file_magic - An "enum class" enumeration of file types based on magic (the first
index 39b33123de8a983a8051bbaac040dffe97434021..4b922da71862571b3a5b562f76df1fc713842c42 100644 (file)
@@ -110,6 +110,12 @@ namespace llvm {
 namespace sys  {
 namespace fs {
 
+TimeValue file_status::getLastModificationTime() {
+  TimeValue Ret;
+  Ret.fromEpochTime(fs_st_mtime);
+  return Ret;
+}
+
 error_code current_path(SmallVectorImpl<char> &result) {
 #ifdef MAXPATHLEN
   result.reserve(MAXPATHLEN);
@@ -401,6 +407,7 @@ error_code status(const Twine &path, file_status &result) {
 
   result.fs_st_dev = status.st_dev;
   result.fs_st_ino = status.st_ino;
+  result.fs_st_mtime = status.st_mtime;
 
   return error_code::success();
 }
index 8815b0ec2f71eeaf4bb440abd592676911e76e0e..006e31a5bd2eb5535f861e5f5f15289589132dc8 100644 (file)
@@ -128,6 +128,16 @@ namespace llvm {
 namespace sys  {
 namespace fs {
 
+TimeValue file_status::getLastModificationTime() {
+  ULARGE_INTEGER UI;
+  UI.LowPart = LastWriteTimeLow;
+  UI.HighPart = LastWriteTimeHigh;
+
+  TimeValue Ret;
+  Ret.fromWin32Time(UI.QuadPart);
+  return Ret;
+}
+
 error_code current_path(SmallVectorImpl<char> &result) {
   SmallVector<wchar_t, 128> cur_path;
   cur_path.reserve(128);
index 4c986715aec713890b3d0974d845aaf449d493fc..e422f310c6bb228152a6865ec25e849f53ef4200 100644 (file)
@@ -583,15 +583,14 @@ doReplaceOrInsert(std::string* ErrMsg) {
     }
 
     if (found != remaining.end()) {
-      std::string Err;
-      sys::PathWithStatus PwS(*found);
-      const sys::FileStatus *si = PwS.getFileStatus(false, &Err);
-      if (!si)
+      sys::fs::file_status Status;
+      error_code EC = sys::fs::status(*found, Status);
+      if (EC)
         return true;
-      if (!si->isDir) {
+      if (!sys::fs::is_directory(Status)) {
         if (OnlyUpdate) {
           // Replace the item only if it is newer.
-          if (si->modTime > I->getModTime())
+          if (Status.getLastModificationTime() > I->getModTime())
             if (I->replaceWith(*found, ErrMsg))
               return true;
         } else {