summaryrefslogtreecommitdiffstats
path: root/base/file_util_posix.cc
diff options
context:
space:
mode:
authoryoshiki@chromium.org <yoshiki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-11 01:24:02 +0000
committeryoshiki@chromium.org <yoshiki@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-07-11 01:24:02 +0000
commit5085e4487f4b1d6c92075e1a1434b8d422adbecc (patch)
treec1ec6d98d3656565a912f802750bb5604a7b45c3 /base/file_util_posix.cc
parenta51ea457256f8cd7249f9c0c363845371494ac60 (diff)
downloadchromium_src-5085e4487f4b1d6c92075e1a1434b8d422adbecc.zip
chromium_src-5085e4487f4b1d6c92075e1a1434b8d422adbecc.tar.gz
chromium_src-5085e4487f4b1d6c92075e1a1434b8d422adbecc.tar.bz2
Add the methods to change and get a posix file permission to file_util.
BUG=134821, 134820 TEST=both base_unittests:FileUtilTest.*, VerifyPathControlledByUserTest.* and unit_tests:Gdata* pass Review URL: https://chromiumcodereview.appspot.com/10756020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@146020 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util_posix.cc')
-rw-r--r--base/file_util_posix.cc34
1 files changed, 34 insertions, 0 deletions
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
index 18e515f..56dc8501 100644
--- a/base/file_util_posix.cc
+++ b/base/file_util_posix.cc
@@ -460,6 +460,40 @@ 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() does not return valid
+ // permission bits in 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);
+
+ // Calls stat() so that we can preserve the higher bits like S_ISGID.
+ stat_wrapper_t stat_buf;
+ if (CallStat(path.value().c_str(), &stat_buf) != 0)
+ return false;
+
+ // Clears the existing permission bits, and adds the new ones.
+ 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;
+}
+
// 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.