Create files with the correct permission instead of changing it afterwards.
authorRafael Espindola <rafael.espindola@gmail.com>
Mon, 8 Jul 2013 16:16:51 +0000 (16:16 +0000)
committerRafael Espindola <rafael.espindola@gmail.com>
Mon, 8 Jul 2013 16:16:51 +0000 (16:16 +0000)
No intended functionality change.

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

tools/llvm-ar/llvm-ar.cpp

index a9297eb05755ed87eebae38072211e885cf9f7c1..bf9447bccf94e89dd65cbee9078b8f093ffd06d7 100644 (file)
@@ -404,7 +404,10 @@ doExtract(std::string* ErrMsg) {
       OpenFlags |= O_BINARY;
 #endif
 
-      int FD = open(I->getPath().str().c_str(), OpenFlags, 0664);
+      // Retain the original mode.
+      sys::fs::perms Mode = sys::fs::perms(I->getMode());
+
+      int FD = open(I->getPath().str().c_str(), OpenFlags, Mode);
       if (FD < 0)
         return true;
 
@@ -419,17 +422,11 @@ doExtract(std::string* ErrMsg) {
         file.write(data, len);
       }
 
-      // Retain the original mode.
-      sys::fs::perms Mode = sys::fs::perms(I->getMode());
-      // FIXME: at least on posix we should be able to reuse FD (fchmod).
-      error_code EC = sys::fs::permissions(I->getPath(), Mode);
-      if (EC)
-        fail(EC.message());
-
       // If we're supposed to retain the original modification times, etc. do so
       // now.
       if (OriginalDates) {
-        EC = sys::fs::setLastModificationAndAccessTime(FD, I->getModTime());
+        error_code EC =
+            sys::fs::setLastModificationAndAccessTime(FD, I->getModTime());
         if (EC)
           fail(EC.message());
       }