| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 } | 200 } |
| 201 | 201 |
| 202 // TODO(erikkay): The Windows version of this accepts paths like "foo/bar/*" | 202 // TODO(erikkay): The Windows version of this accepts paths like "foo/bar/*" |
| 203 // which works both with and without the recursive flag. I'm not sure we need | 203 // which works both with and without the recursive flag. I'm not sure we need |
| 204 // that functionality. If not, remove from file_util_win.cc, otherwise add it | 204 // that functionality. If not, remove from file_util_win.cc, otherwise add it |
| 205 // here. | 205 // here. |
| 206 bool Delete(const FilePath& path, bool recursive) { | 206 bool Delete(const FilePath& path, bool recursive) { |
| 207 base::ThreadRestrictions::AssertIOAllowed(); | 207 base::ThreadRestrictions::AssertIOAllowed(); |
| 208 const char* path_str = path.value().c_str(); | 208 const char* path_str = path.value().c_str(); |
| 209 stat_wrapper_t file_info; | 209 stat_wrapper_t file_info; |
| 210 int test = CallStat(path_str, &file_info); | 210 int test = CallLstat(path_str, &file_info); |
| 211 if (test != 0) { | 211 if (test != 0) { |
| 212 // The Windows version defines this condition as success. | 212 // The Windows version defines this condition as success. |
| 213 bool ret = (errno == ENOENT || errno == ENOTDIR); | 213 bool ret = (errno == ENOENT || errno == ENOTDIR); |
| 214 return ret; | 214 return ret; |
| 215 } | 215 } |
| 216 if (!S_ISDIR(file_info.st_mode)) | 216 if (!S_ISDIR(file_info.st_mode)) |
| 217 return (unlink(path_str) == 0); | 217 return (unlink(path_str) == 0); |
| 218 if (!recursive) | 218 if (!recursive) |
| 219 return (rmdir(path_str) == 0); | 219 return (rmdir(path_str) == 0); |
| 220 | 220 |
| (...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 // time. Check to see if it exists and make sure it is a directory. | 571 // time. Check to see if it exists and make sure it is a directory. |
| 572 if (!DirectoryExists(*i)) | 572 if (!DirectoryExists(*i)) |
| 573 return false; | 573 return false; |
| 574 } | 574 } |
| 575 return true; | 575 return true; |
| 576 } | 576 } |
| 577 | 577 |
| 578 // TODO(rkc): Refactor GetFileInfo and FileEnumerator to handle symlinks | 578 // TODO(rkc): Refactor GetFileInfo and FileEnumerator to handle symlinks |
| 579 // correctly. http://code.google.com/p/chromium-os/issues/detail?id=15948 | 579 // correctly. http://code.google.com/p/chromium-os/issues/detail?id=15948 |
| 580 bool IsLink(const FilePath& file_path) { | 580 bool IsLink(const FilePath& file_path) { |
| 581 struct stat st; | 581 stat_wrapper_t st; |
| 582 // If we can't lstat the file, it's safe to assume that the file won't at | 582 // If we can't lstat the file, it's safe to assume that the file won't at |
| 583 // least be a 'followable' link. | 583 // least be a 'followable' link. |
| 584 if (lstat(file_path.value().c_str(), &st) != 0) | 584 if (CallLstat(file_path.value().c_str(), &st) != 0) |
| 585 return false; | 585 return false; |
| 586 | 586 |
| 587 if (S_ISLNK(st.st_mode)) | 587 if (S_ISLNK(st.st_mode)) |
| 588 return true; | 588 return true; |
| 589 else | 589 else |
| 590 return false; | 590 return false; |
| 591 } | 591 } |
| 592 | 592 |
| 593 bool GetFileInfo(const FilePath& file_path, base::PlatformFileInfo* results) { | 593 bool GetFileInfo(const FilePath& file_path, base::PlatformFileInfo* results) { |
| 594 stat_wrapper_t file_info; | 594 stat_wrapper_t file_info; |
| (...skipping 520 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1115 | 1115 |
| 1116 allowed_group_ids.insert(group_record->gr_gid); | 1116 allowed_group_ids.insert(group_record->gr_gid); |
| 1117 } | 1117 } |
| 1118 | 1118 |
| 1119 return VerifyPathControlledByUser( | 1119 return VerifyPathControlledByUser( |
| 1120 kFileSystemRoot, path, kRootUid, allowed_group_ids); | 1120 kFileSystemRoot, path, kRootUid, allowed_group_ids); |
| 1121 } | 1121 } |
| 1122 #endif // defined(OS_MACOSX) | 1122 #endif // defined(OS_MACOSX) |
| 1123 | 1123 |
| 1124 } // namespace file_util | 1124 } // namespace file_util |
| OLD | NEW |