From a8a9f1baf0c7733f32f2fc513aac1af7233251b4 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Mon, 8 Jul 2013 16:42:01 +0000 Subject: [PATCH] We now always create files with the correct permissions. Simplify the interface. llvm-svn: 185834 --- llvm/include/llvm/Support/FileSystem.h | 13 +--------- llvm/lib/Support/Unix/Path.inc | 32 +----------------------- llvm/lib/Support/Windows/Path.inc | 34 -------------------------- llvm/unittests/Support/Path.cpp | 28 --------------------- 4 files changed, 2 insertions(+), 105 deletions(-) diff --git a/llvm/include/llvm/Support/FileSystem.h b/llvm/include/llvm/Support/FileSystem.h index 194f5f5c6a88..7f6c8f5e2ef1 100644 --- a/llvm/include/llvm/Support/FileSystem.h +++ b/llvm/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/llvm/lib/Support/Unix/Path.inc b/llvm/lib/Support/Unix/Path.inc index e23e0bd6186e..433d187ffdaa 100644 --- a/llvm/lib/Support/Unix/Path.inc +++ b/llvm/lib/Support/Unix/Path.inc @@ -569,7 +569,7 @@ error_code status(const Twine &path, file_status &result) { return ec; } - perms prms = static_cast(status.st_mode & perms_mask); + perms prms = static_cast(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(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/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc index ab59fe883444..735999422ec4 100644 --- a/llvm/lib/Support/Windows/Path.inc +++ b/llvm/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 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/llvm/unittests/Support/Path.cpp b/llvm/unittests/Support/Path.cpp index 7371e30a5ead..9a68e08f9c9c 100644 --- a/llvm/unittests/Support/Path.cpp +++ b/llvm/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; -- GitLab