[llvm] r185834 - We now always create files with the correct permissions. Simplify the interface.

Rafael Espindola rafael.espindola at gmail.com
Mon Jul 8 09:42:01 PDT 2013


Author: rafael
Date: Mon Jul  8 11:42:01 2013
New Revision: 185834

URL: http://llvm.org/viewvc/llvm-project?rev=185834&view=rev
Log:
We now always create files with the correct permissions. Simplify the interface.

Modified:
    llvm/trunk/include/llvm/Support/FileSystem.h
    llvm/trunk/lib/Support/Unix/Path.inc
    llvm/trunk/lib/Support/Windows/Path.inc
    llvm/trunk/unittests/Support/Path.cpp

Modified: llvm/trunk/include/llvm/Support/FileSystem.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/Support/FileSystem.h?rev=185834&r1=185833&r2=185834&view=diff
==============================================================================
--- llvm/trunk/include/llvm/Support/FileSystem.h (original)
+++ llvm/trunk/include/llvm/Support/FileSystem.h Mon Jul  8 11:42:01 2013
@@ -118,11 +118,7 @@ enum perms {
   set_uid_on_exe  = 04000, 
   set_gid_on_exe  = 02000, 
   sticky_bit      = 01000,
-  perms_mask      = all_all | set_uid_on_exe | set_gid_on_exe | sticky_bit, 
-  perms_not_known = 0xFFFF,
-  add_perms       = 0x1000,
-  remove_perms    = 0x2000, 
-  symlink_perms   = 0x4000
+  perms_not_known = 0xFFFF
 };
 
 // Helper functions so that you can use & and | to manipulate perms bits:
@@ -522,13 +518,6 @@ error_code is_symlink(const Twine &path,
 ///          platform specific error_code.
 error_code status(const Twine &path, file_status &result);
 
-/// @brief Modifies permission bits on a file
-///
-/// @param path Input path.
-/// @returns errc::success if permissions have been changed, otherwise a
-///          platform specific error_code.
-error_code permissions(const Twine &path, perms prms);
-
 error_code setLastModificationAndAccessTime(int FD, TimeValue Time);
 
 /// @brief Is status available?

Modified: llvm/trunk/lib/Support/Unix/Path.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Unix/Path.inc?rev=185834&r1=185833&r2=185834&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Unix/Path.inc (original)
+++ llvm/trunk/lib/Support/Unix/Path.inc Mon Jul  8 11:42:01 2013
@@ -569,7 +569,7 @@ error_code status(const Twine &path, fil
     return ec;
   }
 
-  perms prms = static_cast<perms>(status.st_mode & perms_mask);
+  perms prms = static_cast<perms>(status.st_mode);
   
   if (S_ISDIR(status.st_mode))
     result = file_status(file_type::directory_file, prms);
@@ -594,36 +594,6 @@ error_code status(const Twine &path, fil
 
   return error_code::success();
 }
-
-// Modifies permissions on a file.
-error_code permissions(const Twine &path, perms prms) {
-  if ((prms & add_perms) && (prms & remove_perms))
-    llvm_unreachable("add_perms and remove_perms are mutually exclusive");
-
-  // Get current permissions
-  // FIXME: We only need this stat for add_perms and remove_perms.
-  file_status info;
-  if (error_code ec = status(path, info)) {
-    return ec;
-  }
-  
-  // Set updated permissions.
-  SmallString<128> path_storage;
-  StringRef p = path.toNullTerminatedStringRef(path_storage);
-  perms permsToSet;
-  if (prms & add_perms) {
-    permsToSet = (info.permissions() | prms) & perms_mask;
-  } else if (prms & remove_perms) {
-    permsToSet = (info.permissions() & ~prms) & perms_mask;
-  } else {
-    permsToSet = prms & perms_mask;
-  }
-  if (::chmod(p.begin(), static_cast<mode_t>(permsToSet))) {
-    return error_code(errno, system_category()); 
-  }
-
-  return error_code::success();
-}
 
 error_code setLastModificationAndAccessTime(int FD, TimeValue Time) {
 #if defined(HAVE_FUTIMENS)

Modified: llvm/trunk/lib/Support/Windows/Path.inc
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/Windows/Path.inc?rev=185834&r1=185833&r2=185834&view=diff
==============================================================================
--- llvm/trunk/lib/Support/Windows/Path.inc (original)
+++ llvm/trunk/lib/Support/Windows/Path.inc Mon Jul  8 11:42:01 2013
@@ -692,40 +692,6 @@ handle_status_error:
   return error_code::success();
 }
 
-
-// Modifies permissions on a file.
-error_code permissions(const Twine &path, perms prms) {
-#if 0 // verify code below before enabling:
-  // If the permissions bits are not trying to modify
-  // "write" permissions, there is nothing to do.
-  if (!(prms & (owner_write|group_write|others_write)))
-    return error_code::success();
-  
-  SmallString<128> path_storage;
-  SmallVector<wchar_t, 128> path_utf16;
-
-  if (error_code ec = UTF8ToUTF16(path.toStringRef(path_storage),
-                                  path_utf16))
-    return ec;
-
-  DWORD attributes = ::GetFileAttributesW(path_utf16.begin());
-
-  if (prms & add_perms) {
-    attributes &= ~FILE_ATTRIBUTE_READONLY;
-  }
-  else if (prms & remove_perms) {
-    attributes |= FILE_ATTRIBUTE_READONLY;
-  }
-  else {
-    assert(0 && "neither add_perms or remove_perms is set");
-  }
-
-  if ( ! ::SetFileAttributesW(path_utf16.begin(), attributes))
-    return windows_error(::GetLastError());
-#endif    
-  return error_code::success();
-}
-
 error_code setLastModificationAndAccessTime(int FD, TimeValue Time) {
   ULARGE_INTEGER UI;
   UI.QuadPart = Time.toWin32Time();

Modified: llvm/trunk/unittests/Support/Path.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/Path.cpp?rev=185834&r1=185833&r2=185834&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/Path.cpp (original)
+++ llvm/trunk/unittests/Support/Path.cpp Mon Jul  8 11:42:01 2013
@@ -363,34 +363,6 @@ TEST_F(FileSystemTest, Magic) {
   }
 }
 
-#if !defined(_WIN32) // FIXME: Win32 has different permission schema.
-TEST_F(FileSystemTest, Permissions) {
-  // Create a temp file.
-  int FileDescriptor;
-  SmallString<64> TempPath;
-  ASSERT_NO_ERROR(
-      fs::createTemporaryFile("prefix", "temp", FileDescriptor, TempPath));
-
-  // Mark file as read-only
-  const fs::perms AllWrite = fs::owner_write|fs::group_write|fs::others_write;
-  ASSERT_NO_ERROR(fs::permissions(Twine(TempPath), fs::remove_perms|AllWrite));
- 
-  // Verify file is read-only
-  fs::file_status Status;
-  ASSERT_NO_ERROR(fs::status(Twine(TempPath), Status));
-  bool AnyWriteBits = (Status.permissions() & AllWrite);
-  EXPECT_FALSE(AnyWriteBits);
-  
-  // Mark file as read-write
-  ASSERT_NO_ERROR(fs::permissions(Twine(TempPath), fs::add_perms|AllWrite));
-  
-  // Verify file is read-write
-  ASSERT_NO_ERROR(fs::status(Twine(TempPath), Status));
-  AnyWriteBits = (Status.permissions() & AllWrite);
-  EXPECT_TRUE(AnyWriteBits);
-}
-#endif
-
 TEST_F(FileSystemTest, FileMapping) {
   // Create a temp file.
   int FileDescriptor;





More information about the llvm-commits mailing list