Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2291)

Unified Diff: base/file_util_posix.cc

Issue 541022: Fix the case where the browser livelocks if we cannot open a file. (Closed)
Patch Set: Created 10 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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) {
« no previous file with comments | « base/file_util.h ('k') | base/file_util_win.cc » ('j') | base/file_util_win.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698