[llvm] r184450 - Add support for getting the last modification time from a file_status.

Rafael Espindola rafael.espindola at gmail.com
Thu Jun 20 11:42:05 PDT 2013


Author: rafael
Date: Thu Jun 20 13:42:04 2013
New Revision: 184450

URL: http://llvm.org/viewvc/llvm-project?rev=184450&view=rev
Log:
Add support for getting the last modification time from a file_status.

Use that in llvm-ar.cpp to replace a use of sys::PathWithStatus.

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

Modified: llvm/trunk/include/llvm/Support/FileSystem.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FileSystem.h?rev=184450&r1=184449&r2=184450&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/FileSystem.h (original)
+++ llvm/trunk/include/llvm/Support/FileSystem.h Thu Jun 20 13:42:04 2013
@@ -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

Modified: llvm/trunk/lib/Support/Unix/PathV2.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/PathV2.inc?rev=184450&r1=184449&r2=184450&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Unix/PathV2.inc (original)
+++ llvm/trunk/lib/Support/Unix/PathV2.inc Thu Jun 20 13:42:04 2013
@@ -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, fil
 
   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();
 }

Modified: llvm/trunk/lib/Support/Windows/PathV2.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/PathV2.inc?rev=184450&r1=184449&r2=184450&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/PathV2.inc (original)
+++ llvm/trunk/lib/Support/Windows/PathV2.inc Thu Jun 20 13:42:04 2013
@@ -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);

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=184450&r1=184449&r2=184450&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-ar/llvm-ar.cpp (original)
+++ llvm/trunk/tools/llvm-ar/llvm-ar.cpp Thu Jun 20 13:42:04 2013
@@ -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 {





More information about the llvm-commits mailing list