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

Side by Side Diff: base/file_util_posix.cc

Issue 18286004: Move PathExists to base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « base/file_util.h ('k') | base/file_util_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <libgen.h> 10 #include <libgen.h>
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 DCHECK(from_path.value().find('*') == std::string::npos); 220 DCHECK(from_path.value().find('*') == std::string::npos);
221 221
222 char top_dir[PATH_MAX]; 222 char top_dir[PATH_MAX];
223 if (strlcpy(top_dir, from_path.value().c_str(), 223 if (strlcpy(top_dir, from_path.value().c_str(),
224 arraysize(top_dir)) >= arraysize(top_dir)) { 224 arraysize(top_dir)) >= arraysize(top_dir)) {
225 return false; 225 return false;
226 } 226 }
227 227
228 // This function does not properly handle destinations within the source 228 // This function does not properly handle destinations within the source
229 FilePath real_to_path = to_path; 229 FilePath real_to_path = to_path;
230 if (file_util::PathExists(real_to_path)) { 230 if (PathExists(real_to_path)) {
231 real_to_path = MakeAbsoluteFilePath(real_to_path); 231 real_to_path = MakeAbsoluteFilePath(real_to_path);
232 if (real_to_path.empty()) 232 if (real_to_path.empty())
233 return false; 233 return false;
234 } else { 234 } else {
235 real_to_path = MakeAbsoluteFilePath(real_to_path.DirName()); 235 real_to_path = MakeAbsoluteFilePath(real_to_path.DirName());
236 if (real_to_path.empty()) 236 if (real_to_path.empty())
237 return false; 237 return false;
238 } 238 }
239 FilePath real_from_path = MakeAbsoluteFilePath(from_path); 239 FilePath real_from_path = MakeAbsoluteFilePath(from_path);
240 if (real_from_path.empty()) 240 if (real_from_path.empty())
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 } 302 }
303 303
304 current = traversal.Next(); 304 current = traversal.Next();
305 if (!current.empty()) 305 if (!current.empty())
306 from_stat = traversal.GetInfo().stat(); 306 from_stat = traversal.GetInfo().stat();
307 } 307 }
308 308
309 return success; 309 return success;
310 } 310 }
311 311
312 bool PathExists(const FilePath& path) {
313 ThreadRestrictions::AssertIOAllowed();
314 return access(path.value().c_str(), F_OK) == 0;
315 }
316
312 } // namespace base 317 } // namespace base
313 318
314 // ----------------------------------------------------------------------------- 319 // -----------------------------------------------------------------------------
315 320
316 namespace file_util { 321 namespace file_util {
317 322
318 using base::stat_wrapper_t; 323 using base::stat_wrapper_t;
319 using base::CallStat; 324 using base::CallStat;
320 using base::CallLstat; 325 using base::CallLstat;
321 using base::FileEnumerator; 326 using base::FileEnumerator;
322 using base::FilePath; 327 using base::FilePath;
323 using base::MakeAbsoluteFilePath; 328 using base::MakeAbsoluteFilePath;
324 using base::RealPath; 329 using base::RealPath;
325 using base::VerifySpecificPathControlledByUser; 330 using base::VerifySpecificPathControlledByUser;
326 331
327 bool PathExists(const FilePath& path) {
328 base::ThreadRestrictions::AssertIOAllowed();
329 return access(path.value().c_str(), F_OK) == 0;
330 }
331
332 bool PathIsWritable(const FilePath& path) { 332 bool PathIsWritable(const FilePath& path) {
333 base::ThreadRestrictions::AssertIOAllowed(); 333 base::ThreadRestrictions::AssertIOAllowed();
334 return access(path.value().c_str(), W_OK) == 0; 334 return access(path.value().c_str(), W_OK) == 0;
335 } 335 }
336 336
337 bool DirectoryExists(const FilePath& path) { 337 bool DirectoryExists(const FilePath& path) {
338 base::ThreadRestrictions::AssertIOAllowed(); 338 base::ThreadRestrictions::AssertIOAllowed();
339 stat_wrapper_t file_info; 339 stat_wrapper_t file_info;
340 if (CallStat(path.value().c_str(), &file_info) == 0) 340 if (CallStat(path.value().c_str(), &file_info) == 0)
341 return S_ISDIR(file_info.st_mode); 341 return S_ISDIR(file_info.st_mode);
(...skipping 606 matching lines...) Expand 10 before | Expand all | Expand 10 after
948 result = false; 948 result = false;
949 if (HANDLE_EINTR(close(outfile)) < 0) 949 if (HANDLE_EINTR(close(outfile)) < 0)
950 result = false; 950 result = false;
951 951
952 return result; 952 return result;
953 } 953 }
954 #endif // !defined(OS_MACOSX) 954 #endif // !defined(OS_MACOSX)
955 955
956 } // namespace internal 956 } // namespace internal
957 } // namespace base 957 } // namespace base
OLDNEW
« no previous file with comments | « base/file_util.h ('k') | base/file_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698