Add a GetUniqueID that will replace the uniqueID of PathV1.h.
authorRafael Espindola <rafael.espindola@gmail.com>
Tue, 18 Jun 2013 19:34:49 +0000 (19:34 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Tue, 18 Jun 2013 19:34:49 +0000 (19:34 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184217 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Support/FileSystem.h
lib/Support/Unix/PathV2.inc
lib/Support/Windows/PathV2.inc

index 11c78cc93941a3ee6f46d4f511fe76577223fb3d..6de8759dda2da819a009025f78d086c9b439fd82 100644 (file)
@@ -556,6 +556,8 @@ file_magic identify_magic(StringRef magic);
 ///          platform specific error_code.
 error_code identify_magic(const Twine &path, file_magic &result);
 
+error_code GetUniqueID(const Twine Path, uint64_t &Result);
+
 /// This class represents a memory mapped file. It is based on
 /// boost::iostreams::mapped_file.
 class mapped_file_region {
index c98c21d07cce7fa9658a3cea1c75bb497e570191..9ea4f9ed51ad03cc2ed550264a35d2800396f33b 100644 (file)
@@ -350,6 +350,18 @@ error_code file_size(const Twine &path, uint64_t &result) {
   return error_code::success();
 }
 
+error_code GetUniqueID(const Twine Path, uint64_t &Result) {
+  SmallString<128> Storage;
+  StringRef P = Path.toNullTerminatedStringRef(Storage);
+
+  struct stat Status;
+  if (::stat(P.begin(), &Status) != 0)
+    return error_code(errno, system_category());
+
+  Result = Status.st_ino;
+  return error_code::success();
+}
+
 error_code status(const Twine &path, file_status &result) {
   SmallString<128> path_storage;
   StringRef p = path.toNullTerminatedStringRef(path_storage);
index ea383895f2a65b0afa074cad05b55cee83cbd23a..3b2992d5a3011b6573b83635b55ac5b5d892f55e 100644 (file)
@@ -413,6 +413,20 @@ error_code file_size(const Twine &path, uint64_t &result) {
   return error_code::success();
 }
 
+error_code GetUniqueID(const Twine Path, uint64_t &Result) {
+  // FIXME: this is only unique if the file is accessed by the same file path.
+  // How do we do this for C:\dir\file and ..\dir\file ? Unix has inode
+  // numbers, but the concept doesn't exist in Windows.
+  SmallString<128> Storage;
+  StringRef P = Path.toStringRef(Storage);
+  uint64_t UniqueID = 0;
+  for (StringRef::iterator I = P.begin(), E = P.end(); I != E; ++I)
+    UniqueID += *I;
+  Result = UniqueID;
+
+  return error_code::success();
+}
+
 static bool isReservedName(StringRef path) {
   // This list of reserved names comes from MSDN, at:
   // http://msdn.microsoft.com/en-us/library/aa365247%28v=vs.85%29.aspx