mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2024-12-27 13:30:05 +00:00
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
This commit is contained in:
parent
a2030eedf1
commit
1cce797d32
@ -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?
|
||||
|
@ -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];
|
||||
|
@ -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();
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user