Chromium Code Reviews| Index: base/file_util_posix.cc |
| diff --git a/base/file_util_posix.cc b/base/file_util_posix.cc |
| index 579e79a34b87e5ba52aa570c624f42a3f925c98c..5be5f5b73d9a327d4259d56a10e973e643332c4a 100644 |
| --- a/base/file_util_posix.cc |
| +++ b/base/file_util_posix.cc |
| @@ -303,24 +303,22 @@ bool PathExists(const FilePath& path) { |
| return CallStat(path.value().c_str(), &file_info) == 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) { |
| +static bool PathAccess(const FilePath& path, int mode) { |
| + int r = access(path.value().c_str(), mode); |
| + if (r == -1 && errno == ENOENT) { |
| // If the path doesn't exist, test the parent dir. |
|
wtc
2010/01/12 19:51:02
Do you know why we do this? This behavior is not
|
| - test_path = test_path.DirName(); |
| - // If the parent dir doesn't exist, then return false (the path is not |
| - // directly writable). |
| - if (CallStat(test_path.value().c_str(), &file_info) != 0) |
| - return false; |
| + r = access(path.DirName().value().c_str(), mode); |
| } |
| - 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 r == 0; |
| +} |
| + |
| +bool PathIsReadable(const FilePath& path) { |
| + return PathAccess(path, R_OK); |
| +} |
| + |
| +bool PathIsWritable(const FilePath& path) { |
| + return PathAccess(path, W_OK); |
| } |
| bool DirectoryExists(const FilePath& path) { |