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

Side by Side Diff: base/file_util.h

Issue 13315: Move file enumeration to filepaths. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 12 years 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_path.cc ('k') | base/file_util_posix.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) 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 // This file contains utility functions for dealing with the local 5 // This file contains utility functions for dealing with the local
6 // filesystem. 6 // filesystem.
7 7
8 #ifndef BASE_FILE_UTIL_H_ 8 #ifndef BASE_FILE_UTIL_H_
9 #define BASE_FILE_UTIL_H_ 9 #define BASE_FILE_UTIL_H_
10 10
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 bool EndsWithSeparator(const FilePath& path); 44 bool EndsWithSeparator(const FilePath& path);
45 // These two versions are both deprecated. TODO(estade): remove them. 45 // These two versions are both deprecated. TODO(estade): remove them.
46 bool EndsWithSeparator(std::wstring* path); 46 bool EndsWithSeparator(std::wstring* path);
47 bool EndsWithSeparator(const std::wstring& path); 47 bool EndsWithSeparator(const std::wstring& path);
48 48
49 // Makes sure that |path| ends with a separator IFF path is a directory that 49 // Makes sure that |path| ends with a separator IFF path is a directory that
50 // exists. Returns true if |path| is an existing directory, false otherwise. 50 // exists. Returns true if |path| is an existing directory, false otherwise.
51 bool EnsureEndsWithSeparator(FilePath* path); 51 bool EnsureEndsWithSeparator(FilePath* path);
52 52
53 // Modifies a string by trimming all trailing separators from the end. 53 // Modifies a string by trimming all trailing separators from the end.
54 // Deprecated. FilePath does this automatically, and if it's constructed from a
55 // path with a trailing separator, StripTrailingSeparators() may be used.
54 void TrimTrailingSeparator(std::wstring* dir); 56 void TrimTrailingSeparator(std::wstring* dir);
55 57
56 // Strips the topmost directory from the end of 'dir'. Assumes 'dir' does not 58 // Strips the topmost directory from the end of 'dir'. Assumes 'dir' does not
57 // refer to a file. 59 // refer to a file.
58 // If 'dir' is a root directory, return without change. 60 // If 'dir' is a root directory, return without change.
59 // Deprecated. Use FilePath::DirName instead. 61 // Deprecated. Use FilePath::DirName instead.
60 void UpOneDirectory(std::wstring* dir); 62 void UpOneDirectory(std::wstring* dir);
61 // Strips the topmost directory from the end of 'dir'. Assumes 'dir' does not 63 // Strips the topmost directory from the end of 'dir'. Assumes 'dir' does not
62 // refer to a file. 64 // refer to a file.
63 // If 'dir' is a root directory, the result becomes empty string. 65 // If 'dir' is a root directory, the result becomes empty string.
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 // 368 //
367 // |pattern| is an optional pattern for which files to match. This 369 // |pattern| is an optional pattern for which files to match. This
368 // works like shell globbing. For example, "*.txt" or "Foo???.doc". 370 // works like shell globbing. For example, "*.txt" or "Foo???.doc".
369 // However, be careful in specifying patterns that aren't cross platform 371 // However, be careful in specifying patterns that aren't cross platform
370 // since the underlying code uses OS-specific matching routines. In general, 372 // since the underlying code uses OS-specific matching routines. In general,
371 // Windows matching is less featureful than others, so test there first. 373 // Windows matching is less featureful than others, so test there first.
372 // If unspecified, this will match all files. 374 // If unspecified, this will match all files.
373 // NOTE: the pattern only matches the contents of root_path, not files in 375 // NOTE: the pattern only matches the contents of root_path, not files in
374 // recursive subdirectories. 376 // recursive subdirectories.
375 // TODO(erikkay): Fix the pattern matching to work at all levels. 377 // TODO(erikkay): Fix the pattern matching to work at all levels.
376 FileEnumerator(const std::wstring& root_path, 378 FileEnumerator(const FilePath& root_path,
377 bool recursive, 379 bool recursive,
378 FileEnumerator::FILE_TYPE file_type); 380 FileEnumerator::FILE_TYPE file_type);
379 FileEnumerator(const std::wstring& root_path, 381 FileEnumerator(const FilePath& root_path,
380 bool recursive, 382 bool recursive,
381 FileEnumerator::FILE_TYPE file_type, 383 FileEnumerator::FILE_TYPE file_type,
382 const std::wstring& pattern); 384 const FilePath::StringType& pattern);
383 ~FileEnumerator(); 385 ~FileEnumerator();
384 386
385 // Returns an empty string if there are no more results. 387 // Returns an empty string if there are no more results.
386 std::wstring Next(); 388 FilePath Next();
387 389
388 // Write the file info into |info|. 390 // Write the file info into |info|.
389 void GetFindInfo(FindInfo* info); 391 void GetFindInfo(FindInfo* info);
390 392
391 private: 393 private:
392 std::wstring root_path_; 394 FilePath root_path_;
393 bool recursive_; 395 bool recursive_;
394 FILE_TYPE file_type_; 396 FILE_TYPE file_type_;
395 std::wstring pattern_; // Empty when we want to find everything. 397 FilePath pattern_; // Empty when we want to find everything.
396 398
397 // Set to true when there is a find operation open. This way, we can lazily 399 // Set to true when there is a find operation open. This way, we can lazily
398 // start the operations when the caller calls Next(). 400 // start the operations when the caller calls Next().
399 bool is_in_find_op_; 401 bool is_in_find_op_;
400 402
401 // A stack that keeps track of which subdirectories we still need to 403 // A stack that keeps track of which subdirectories we still need to
402 // enumerate in the breadth-first search. 404 // enumerate in the breadth-first search.
403 std::stack<std::wstring> pending_paths_; 405 std::stack<FilePath> pending_paths_;
404 406
405 #if defined(OS_WIN) 407 #if defined(OS_WIN)
406 WIN32_FIND_DATA find_data_; 408 WIN32_FIND_DATA find_data_;
407 HANDLE find_handle_; 409 HANDLE find_handle_;
408 #elif defined(OS_POSIX) 410 #elif defined(OS_POSIX)
409 FTS* fts_; 411 FTS* fts_;
410 FTSENT* fts_ent_; 412 FTSENT* fts_ent_;
411 #endif 413 #endif
412 414
413 DISALLOW_EVIL_CONSTRUCTORS(FileEnumerator); 415 DISALLOW_EVIL_CONSTRUCTORS(FileEnumerator);
414 }; 416 };
415 417
416 // Renames a file using the SHFileOperation API to ensure that the target file 418 // Renames a file using the SHFileOperation API to ensure that the target file
417 // gets the correct default security descriptor in the new path. 419 // gets the correct default security descriptor in the new path.
418 bool RenameFileAndResetSecurityDescriptor( 420 bool RenameFileAndResetSecurityDescriptor(
419 const std::wstring& source_file_path, 421 const std::wstring& source_file_path,
420 const std::wstring& target_file_path); 422 const std::wstring& target_file_path);
421 423
422 } // namespace file_util 424 } // namespace file_util
423 425
424 #endif // BASE_FILE_UTIL_H_ 426 #endif // BASE_FILE_UTIL_H_
OLDNEW
« no previous file with comments | « base/file_path.cc ('k') | base/file_util_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698