summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRafael Espindola <rafael.espindola@gmail.com>2013-07-08 16:42:01 +0000
committerRafael Espindola <rafael.espindola@gmail.com>2013-07-08 16:42:01 +0000
commit1cce797d32aa465c054fc4a313d8c330c89bd862 (patch)
treefd5deb37366d1dbb249abe24d6bcfdcb3f777853
parenta2030eedf1094ef8508ca90341c5a7ec8f638308 (diff)
downloadllvm-1cce797d32aa465c054fc4a313d8c330c89bd862.tar.gz
llvm-1cce797d32aa465c054fc4a313d8c330c89bd862.tar.bz2
llvm-1cce797d32aa465c054fc4a313d8c330c89bd862.tar.xz
We now always create files with the correct permissions. Simplify the interface.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@185834 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/llvm/Support/FileSystem.h13
-rw-r--r--lib/Support/Unix/Path.inc32
-rw-r--r--lib/Support/Windows/Path.inc34
-rw-r--r--unittests/Support/Path.cpp28
4 files changed, 2 insertions, 105 deletions
diff --git a/include/llvm/Support/FileSystem.h b/include/llvm/Support/FileSystem.h
index 194f5f5c6a..7f6c8f5e2e 100644
--- a/include/llvm/Support/FileSystem.h
+++ b/include/llvm/Support/FileSystem.h
@@ -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, bool &result);
/// 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?
diff --git a/lib/Support/Unix/Path.inc b/lib/Support/Unix/Path.inc
index e23e0bd618..433d187ffd 100644
--- a/lib/Support/Unix/Path.inc
+++ b/lib/Support/Unix/Path.inc
@@ -569,7 +569,7 @@ error_code status(const Twine &path, file_status &result) {
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);
@@ -595,36 +595,6 @@ error_code status(const Twine &path, file_status &result) {
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)
timespec Times[2];
diff --git a/lib/Support/Windows/Path.inc b/lib/Support/Windows/Path.inc
index ab59fe8834..735999422e 100644
--- a/lib/Support/Windows/Path.inc
+++ b/lib/Support/Windows/Path.inc
@@ -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();
diff --git a/unittests/Support/Path.cpp b/unittests/Support/Path.cpp
index 7371e30a5e..9a68e08f9c 100644
--- a/unittests/Support/Path.cpp
+++ b/unittests/Support/Path.cpp
@@ -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;