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 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 | 52 |
53 #if !defined(OS_IOS) | 53 #if !defined(OS_IOS) |
54 #include <grp.h> | 54 #include <grp.h> |
55 #endif | 55 #endif |
56 | 56 |
57 #if defined(OS_CHROMEOS) | 57 #if defined(OS_CHROMEOS) |
58 #include "base/chromeos/chromeos_version.h" | 58 #include "base/chromeos/chromeos_version.h" |
59 #endif | 59 #endif |
60 | 60 |
61 using base::FilePath; | 61 using base::FilePath; |
| 62 using base::MakeAbsoluteFilePath; |
| 63 |
| 64 namespace base { |
| 65 |
| 66 FilePath MakeAbsoluteFilePath(const FilePath& input) { |
| 67 base::ThreadRestrictions::AssertIOAllowed(); |
| 68 char full_path[PATH_MAX]; |
| 69 if (realpath(input.value().c_str(), full_path) == NULL) |
| 70 return FilePath(); |
| 71 return FilePath(full_path); |
| 72 } |
| 73 |
| 74 } // namespace base |
62 | 75 |
63 namespace file_util { | 76 namespace file_util { |
64 | 77 |
65 namespace { | 78 namespace { |
66 | 79 |
67 #if defined(OS_BSD) || defined(OS_MACOSX) | 80 #if defined(OS_BSD) || defined(OS_MACOSX) |
68 typedef struct stat stat_wrapper_t; | 81 typedef struct stat stat_wrapper_t; |
69 static int CallStat(const char *path, stat_wrapper_t *sb) { | 82 static int CallStat(const char *path, stat_wrapper_t *sb) { |
70 base::ThreadRestrictions::AssertIOAllowed(); | 83 base::ThreadRestrictions::AssertIOAllowed(); |
71 return stat(path, sb); | 84 return stat(path, sb); |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
143 return base::StringPrintf(".%s.XXXXXX", base::mac::BaseBundleID()); | 156 return base::StringPrintf(".%s.XXXXXX", base::mac::BaseBundleID()); |
144 #endif | 157 #endif |
145 | 158 |
146 #if defined(GOOGLE_CHROME_BUILD) | 159 #if defined(GOOGLE_CHROME_BUILD) |
147 return std::string(".com.google.Chrome.XXXXXX"); | 160 return std::string(".com.google.Chrome.XXXXXX"); |
148 #else | 161 #else |
149 return std::string(".org.chromium.Chromium.XXXXXX"); | 162 return std::string(".org.chromium.Chromium.XXXXXX"); |
150 #endif | 163 #endif |
151 } | 164 } |
152 | 165 |
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, | 166 int CountFilesCreatedAfter(const FilePath& path, |
163 const base::Time& comparison_time) { | 167 const base::Time& comparison_time) { |
164 base::ThreadRestrictions::AssertIOAllowed(); | 168 base::ThreadRestrictions::AssertIOAllowed(); |
165 int file_count = 0; | 169 int file_count = 0; |
166 | 170 |
167 DIR* dir = opendir(path.value().c_str()); | 171 DIR* dir = opendir(path.value().c_str()); |
168 if (dir) { | 172 if (dir) { |
169 #if !defined(OS_LINUX) && !defined(OS_MACOSX) && !defined(OS_BSD) && \ | 173 #if !defined(OS_LINUX) && !defined(OS_MACOSX) && !defined(OS_BSD) && \ |
170 !defined(OS_SOLARIS) && !defined(OS_ANDROID) | 174 !defined(OS_SOLARIS) && !defined(OS_ANDROID) |
171 #error Port warning: depending on the definition of struct dirent, \ | 175 #error Port warning: depending on the definition of struct dirent, \ |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
294 | 298 |
295 char top_dir[PATH_MAX]; | 299 char top_dir[PATH_MAX]; |
296 if (base::strlcpy(top_dir, from_path.value().c_str(), | 300 if (base::strlcpy(top_dir, from_path.value().c_str(), |
297 arraysize(top_dir)) >= arraysize(top_dir)) { | 301 arraysize(top_dir)) >= arraysize(top_dir)) { |
298 return false; | 302 return false; |
299 } | 303 } |
300 | 304 |
301 // This function does not properly handle destinations within the source | 305 // This function does not properly handle destinations within the source |
302 FilePath real_to_path = to_path; | 306 FilePath real_to_path = to_path; |
303 if (PathExists(real_to_path)) { | 307 if (PathExists(real_to_path)) { |
304 if (!AbsolutePath(&real_to_path)) | 308 real_to_path = MakeAbsoluteFilePath(real_to_path); |
| 309 if (real_to_path.empty()) |
305 return false; | 310 return false; |
306 } else { | 311 } else { |
307 real_to_path = real_to_path.DirName(); | 312 real_to_path = MakeAbsoluteFilePath(real_to_path.DirName()); |
308 if (!AbsolutePath(&real_to_path)) | 313 if (real_to_path.empty()) |
309 return false; | 314 return false; |
310 } | 315 } |
311 FilePath real_from_path = from_path; | 316 FilePath real_from_path = MakeAbsoluteFilePath(from_path); |
312 if (!AbsolutePath(&real_from_path)) | 317 if (real_from_path.empty()) |
313 return false; | 318 return false; |
314 if (real_to_path.value().size() >= real_from_path.value().size() && | 319 if (real_to_path.value().size() >= real_from_path.value().size() && |
315 real_to_path.value().compare(0, real_from_path.value().size(), | 320 real_to_path.value().compare(0, real_from_path.value().size(), |
316 real_from_path.value()) == 0) | 321 real_from_path.value()) == 0) |
317 return false; | 322 return false; |
318 | 323 |
319 bool success = true; | 324 bool success = true; |
320 int traverse_type = FileEnumerator::FILES | FileEnumerator::SHOW_SYM_LINKS; | 325 int traverse_type = FileEnumerator::FILES | FileEnumerator::SHOW_SYM_LINKS; |
321 if (recursive) | 326 if (recursive) |
322 traverse_type |= FileEnumerator::DIRECTORIES; | 327 traverse_type |= FileEnumerator::DIRECTORIES; |
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1091 kFileSystemRoot, path, kRootUid, allowed_group_ids); | 1096 kFileSystemRoot, path, kRootUid, allowed_group_ids); |
1092 } | 1097 } |
1093 #endif // defined(OS_MACOSX) && !defined(OS_IOS) | 1098 #endif // defined(OS_MACOSX) && !defined(OS_IOS) |
1094 | 1099 |
1095 int GetMaximumPathComponentLength(const FilePath& path) { | 1100 int GetMaximumPathComponentLength(const FilePath& path) { |
1096 base::ThreadRestrictions::AssertIOAllowed(); | 1101 base::ThreadRestrictions::AssertIOAllowed(); |
1097 return pathconf(path.value().c_str(), _PC_NAME_MAX); | 1102 return pathconf(path.value().c_str(), _PC_NAME_MAX); |
1098 } | 1103 } |
1099 | 1104 |
1100 } // namespace file_util | 1105 } // namespace file_util |
OLD | NEW |