summaryrefslogtreecommitdiffstats
path: root/base
diff options
context:
space:
mode:
authoragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-17 15:01:22 +0000
committeragl@chromium.org <agl@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-05-17 15:01:22 +0000
commitef944e059c2a1bde47f19f8d87a86742f766d94c (patch)
tree934af24805fcbab1466729a570f7629a10bae969 /base
parentb6140d086d71667131111b1c85090e7023311942 (diff)
downloadchromium_src-ef944e059c2a1bde47f19f8d87a86742f766d94c.zip
chromium_src-ef944e059c2a1bde47f19f8d87a86742f766d94c.tar.gz
chromium_src-ef944e059c2a1bde47f19f8d87a86742f766d94c.tar.bz2
Use access instead of stat in PathExists and PathIsWritable.
This change fixes the issue where PathIsWritable returns the wrong answer when called by the superuser. It also slightly simplifies the code. This fix is helpful for Chrome OS because Chrome OS uses PathIsWritable in backlight-tool TEST=Verified that this change fixes backlight-tool (part of the Chrome OS power manager). BUG=none Patch by davidjames http://codereview.chromium.org/2073005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@47418 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base')
-rw-r--r--base/file_util_posix.cc15
1 files changed, 2 insertions, 13 deletions
diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc
index f468f28..bd1711b 100644
--- a/base/file_util_posix.cc
+++ b/base/file_util_posix.cc
@@ -294,22 +294,11 @@ bool CopyDirectory(const FilePath& from_path,
}
bool PathExists(const FilePath& path) {
- stat_wrapper_t file_info;
- return CallStat(path.value().c_str(), &file_info) == 0;
+ return access(path.value().c_str(), F_OK) == 0;
}
bool PathIsWritable(const FilePath& path) {
- FilePath test_path(path);
- stat_wrapper_t file_info;
- if (CallStat(test_path.value().c_str(), &file_info) != 0)
- return false;
- if (S_IWOTH & file_info.st_mode)
- return true;
- if (getegid() == file_info.st_gid && (S_IWGRP & file_info.st_mode))
- return true;
- if (geteuid() == file_info.st_uid && (S_IWUSR & file_info.st_mode))
- return true;
- return false;
+ return access(path.value().c_str(), W_OK) == 0;
}
bool DirectoryExists(const FilePath& path) {