| 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 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 143 return base::StringPrintf(".%s.XXXXXX", base::mac::BaseBundleID()); | 143 return base::StringPrintf(".%s.XXXXXX", base::mac::BaseBundleID()); |
| 144 #endif | 144 #endif |
| 145 | 145 |
| 146 #if defined(GOOGLE_CHROME_BUILD) | 146 #if defined(GOOGLE_CHROME_BUILD) |
| 147 return std::string(".com.google.Chrome.XXXXXX"); | 147 return std::string(".com.google.Chrome.XXXXXX"); |
| 148 #else | 148 #else |
| 149 return std::string(".org.chromium.Chromium.XXXXXX"); | 149 return std::string(".org.chromium.Chromium.XXXXXX"); |
| 150 #endif | 150 #endif |
| 151 } | 151 } |
| 152 | 152 |
| 153 bool AbsolutePath(FilePath* path) { | |
| 154 base::ThreadRestrictions::AssertIOAllowed(); // For realpath(). | |
| 155 char full_path[PATH_MAX]; | |
| 156 if (realpath(path->value().c_str(), full_path) == NULL) | |
| 157 return false; | |
| 158 *path = FilePath(full_path); | |
| 159 return true; | |
| 160 } | |
| 161 | |
| 162 int CountFilesCreatedAfter(const FilePath& path, | 153 int CountFilesCreatedAfter(const FilePath& path, |
| 163 const base::Time& comparison_time) { | 154 const base::Time& comparison_time) { |
| 164 base::ThreadRestrictions::AssertIOAllowed(); | 155 base::ThreadRestrictions::AssertIOAllowed(); |
| 165 int file_count = 0; | 156 int file_count = 0; |
| 166 | 157 |
| 167 DIR* dir = opendir(path.value().c_str()); | 158 DIR* dir = opendir(path.value().c_str()); |
| 168 if (dir) { | 159 if (dir) { |
| 169 #if !defined(OS_LINUX) && !defined(OS_MACOSX) && !defined(OS_BSD) && \ | 160 #if !defined(OS_LINUX) && !defined(OS_MACOSX) && !defined(OS_BSD) && \ |
| 170 !defined(OS_SOLARIS) && !defined(OS_ANDROID) | 161 !defined(OS_SOLARIS) && !defined(OS_ANDROID) |
| 171 #error Port warning: depending on the definition of struct dirent, \ | 162 #error Port warning: depending on the definition of struct dirent, \ |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 | 285 |
| 295 char top_dir[PATH_MAX]; | 286 char top_dir[PATH_MAX]; |
| 296 if (base::strlcpy(top_dir, from_path.value().c_str(), | 287 if (base::strlcpy(top_dir, from_path.value().c_str(), |
| 297 arraysize(top_dir)) >= arraysize(top_dir)) { | 288 arraysize(top_dir)) >= arraysize(top_dir)) { |
| 298 return false; | 289 return false; |
| 299 } | 290 } |
| 300 | 291 |
| 301 // This function does not properly handle destinations within the source | 292 // This function does not properly handle destinations within the source |
| 302 FilePath real_to_path = to_path; | 293 FilePath real_to_path = to_path; |
| 303 if (PathExists(real_to_path)) { | 294 if (PathExists(real_to_path)) { |
| 304 if (!AbsolutePath(&real_to_path)) | 295 real_to_path = real_to_path.AsAbsolute(); |
| 296 if (real_to_path.empty()) |
| 305 return false; | 297 return false; |
| 306 } else { | 298 } else { |
| 307 real_to_path = real_to_path.DirName(); | 299 real_to_path = real_to_path.DirName().AsAbsolute(); |
| 308 if (!AbsolutePath(&real_to_path)) | 300 if (real_to_path.empty()) |
| 309 return false; | 301 return false; |
| 310 } | 302 } |
| 311 FilePath real_from_path = from_path; | 303 FilePath real_from_path = from_path.AsAbsolute(); |
| 312 if (!AbsolutePath(&real_from_path)) | 304 if (real_from_path.empty()) |
| 313 return false; | 305 return false; |
| 314 if (real_to_path.value().size() >= real_from_path.value().size() && | 306 if (real_to_path.value().size() >= real_from_path.value().size() && |
| 315 real_to_path.value().compare(0, real_from_path.value().size(), | 307 real_to_path.value().compare(0, real_from_path.value().size(), |
| 316 real_from_path.value()) == 0) | 308 real_from_path.value()) == 0) |
| 317 return false; | 309 return false; |
| 318 | 310 |
| 319 bool success = true; | 311 bool success = true; |
| 320 int traverse_type = FileEnumerator::FILES | FileEnumerator::SHOW_SYM_LINKS; | 312 int traverse_type = FileEnumerator::FILES | FileEnumerator::SHOW_SYM_LINKS; |
| 321 if (recursive) | 313 if (recursive) |
| 322 traverse_type |= FileEnumerator::DIRECTORIES; | 314 traverse_type |= FileEnumerator::DIRECTORIES; |
| (...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1091 kFileSystemRoot, path, kRootUid, allowed_group_ids); | 1083 kFileSystemRoot, path, kRootUid, allowed_group_ids); |
| 1092 } | 1084 } |
| 1093 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 1085 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
| 1094 | 1086 |
| 1095 int GetMaximumPathComponentLength(const FilePath& path) { | 1087 int GetMaximumPathComponentLength(const FilePath& path) { |
| 1096 base::ThreadRestrictions::AssertIOAllowed(); | 1088 base::ThreadRestrictions::AssertIOAllowed(); |
| 1097 return pathconf(path.value().c_str(), _PC_NAME_MAX); | 1089 return pathconf(path.value().c_str(), _PC_NAME_MAX); |
| 1098 } | 1090 } |
| 1099 | 1091 |
| 1100 } // namespace file_util | 1092 } // namespace file_util |
| OLD | NEW |