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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/file_util.h" 5 #include "base/file_util.h"
6 6
7 #include <dirent.h> 7 #include <dirent.h>
8 #include <errno.h> 8 #include <errno.h>
9 #include <fcntl.h> 9 #include <fcntl.h>
10 #include <fnmatch.h> 10 #include <fnmatch.h>
(...skipping 285 matching lines...) Expand 10 before | Expand all | Expand 10 after
296 } 296 }
297 297
298 return success; 298 return success;
299 } 299 }
300 300
301 bool PathExists(const FilePath& path) { 301 bool PathExists(const FilePath& path) {
302 stat_wrapper_t file_info; 302 stat_wrapper_t file_info;
303 return CallStat(path.value().c_str(), &file_info) == 0; 303 return CallStat(path.value().c_str(), &file_info) == 0;
304 } 304 }
305 305
306 static bool PathAccess(const FilePath& path, int mode) {
307 int r = access(path.value().c_str(), mode);
308 if (r == -1 && errno == ENOENT) {
309 // 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
310 r = access(path.DirName().value().c_str(), mode);
311 }
312
313 return r == 0;
314 }
315
316 bool PathIsReadable(const FilePath& path) {
317 return PathAccess(path, R_OK);
318 }
319
306 bool PathIsWritable(const FilePath& path) { 320 bool PathIsWritable(const FilePath& path) {
307 FilePath test_path(path); 321 return PathAccess(path, W_OK);
308 stat_wrapper_t file_info;
309 if (CallStat(test_path.value().c_str(), &file_info) != 0) {
310 // If the path doesn't exist, test the parent dir.
311 test_path = test_path.DirName();
312 // If the parent dir doesn't exist, then return false (the path is not
313 // directly writable).
314 if (CallStat(test_path.value().c_str(), &file_info) != 0)
315 return false;
316 }
317 if (S_IWOTH & file_info.st_mode)
318 return true;
319 if (getegid() == file_info.st_gid && (S_IWGRP & file_info.st_mode))
320 return true;
321 if (geteuid() == file_info.st_uid && (S_IWUSR & file_info.st_mode))
322 return true;
323 return false;
324 } 322 }
325 323
326 bool DirectoryExists(const FilePath& path) { 324 bool DirectoryExists(const FilePath& path) {
327 stat_wrapper_t file_info; 325 stat_wrapper_t file_info;
328 if (CallStat(path.value().c_str(), &file_info) == 0) 326 if (CallStat(path.value().c_str(), &file_info) == 0)
329 return S_ISDIR(file_info.st_mode); 327 return S_ISDIR(file_info.st_mode);
330 return false; 328 return false;
331 } 329 }
332 330
333 // TODO(erikkay): implement 331 // TODO(erikkay): implement
(...skipping 368 matching lines...) Expand 10 before | Expand all | Expand 10 after
702 length_ = 0; 700 length_ = 0;
703 file_ = base::kInvalidPlatformFileValue; 701 file_ = base::kInvalidPlatformFileValue;
704 } 702 }
705 703
706 bool HasFileBeenModifiedSince(const FileEnumerator::FindInfo& find_info, 704 bool HasFileBeenModifiedSince(const FileEnumerator::FindInfo& find_info,
707 const base::Time& cutoff_time) { 705 const base::Time& cutoff_time) {
708 return find_info.stat.st_mtime >= cutoff_time.ToTimeT(); 706 return find_info.stat.st_mtime >= cutoff_time.ToTimeT();
709 } 707 }
710 708
711 } // namespace file_util 709 } // namespace file_util
OLDNEW
« 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