| Index: base/file_util_posix.cc
|
| diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
|
| index e3bab95dd8e32554c81d8b41466909e5406e0027..8647df5edca9049b37f3b4a429dcc2f39f405260 100644
|
| --- a/base/file_util_posix.cc
|
| +++ b/base/file_util_posix.cc
|
| @@ -457,6 +457,60 @@ bool ReadSymbolicLink(const FilePath& symlink_path,
|
| return true;
|
| }
|
|
|
| +bool GetPosixFilePermissions(const FilePath& path, int* mode) {
|
| + base::ThreadRestrictions::AssertIOAllowed();
|
| + DCHECK(mode);
|
| +
|
| + stat_wrapper_t file_info;
|
| + // Uses stat(), because on symbolic link, lstat() may not return valid
|
| + // information in the permission bits st_mode.
|
| + if (CallStat(path.value().c_str(), &file_info) != 0)
|
| + return false;
|
| +
|
| + *mode = file_info.st_mode & FILE_PERMISSION_MASK;
|
| + return true;
|
| +}
|
| +
|
| +bool SetPosixFilePermissions(const FilePath& path,
|
| + int mode) {
|
| + base::ThreadRestrictions::AssertIOAllowed();
|
| + DCHECK((mode & ~FILE_PERMISSION_MASK) == 0);
|
| +
|
| + stat_wrapper_t stat_buf;
|
| + if (CallStat(path.value().c_str(), &stat_buf) != 0)
|
| + return false;
|
| +
|
| + mode_t updated_mode_bits = stat_buf.st_mode & ~FILE_PERMISSION_MASK;
|
| + updated_mode_bits |= mode & FILE_PERMISSION_MASK;
|
| +
|
| + if (HANDLE_EINTR(chmod(path.value().c_str(), updated_mode_bits)) != 0)
|
| + return false;
|
| +
|
| + return true;
|
| +}
|
| +
|
| +bool ChangePosixFilePermissions(const FilePath& path,
|
| + int mode_bits_to_set,
|
| + int mode_bits_to_clear) {
|
| + base::ThreadRestrictions::AssertIOAllowed();
|
| + DCHECK((mode_bits_to_set & ~FILE_PERMISSION_MASK) == 0);
|
| + DCHECK((mode_bits_to_clear & ~FILE_PERMISSION_MASK) == 0);
|
| + DCHECK(!(mode_bits_to_set & mode_bits_to_clear))
|
| + << "Can't set and clear the same bits.";
|
| +
|
| + int mode;
|
| + if (!GetPosixFilePermissions(path, &mode))
|
| + return false;
|
| +
|
| + mode |= mode_bits_to_set;
|
| + mode &= ~mode_bits_to_clear;
|
| +
|
| + if (SetPosixFilePermissions(path, mode))
|
| + return false;
|
| +
|
| + return true;
|
| +}
|
| +
|
| // Creates and opens a temporary file in |directory|, returning the
|
| // file descriptor. |path| is set to the temporary file path.
|
| // This function does NOT unlink() the file.
|
|
|