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

Side by Side Diff: base/file_util.h

Issue 11507: Port directory lister. Don't break mac build. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 12 years, 1 month 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 | « no previous file | 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
11 #include "build/build_config.h" 11 #include "build/build_config.h"
12 12
13 #if defined(OS_WIN) 13 #if defined(OS_WIN)
14 #include <windows.h> 14 #include <windows.h>
15 #elif defined(OS_POSIX) 15 #elif defined(OS_POSIX)
16 #include <fts.h> 16 #include <fts.h>
17 #include <sys/stat.h>
17 #endif 18 #endif
18 19
19 #include <stdio.h> 20 #include <stdio.h>
20 21
21 #include <stack> 22 #include <stack>
22 #include <string> 23 #include <string>
23 #include <vector> 24 #include <vector>
24 25
25 #include "base/basictypes.h" 26 #include "base/basictypes.h"
26 27
(...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after
316 // Deprecated temporary compatibility function. 317 // Deprecated temporary compatibility function.
317 bool SetCurrentDirectory(const std::wstring& current_directory); 318 bool SetCurrentDirectory(const std::wstring& current_directory);
318 319
319 // A class for enumerating the files in a provided path. The order of the 320 // A class for enumerating the files in a provided path. The order of the
320 // results is not guaranteed. 321 // results is not guaranteed.
321 // 322 //
322 // DO NOT USE FROM THE MAIN THREAD of your application unless it is a test 323 // DO NOT USE FROM THE MAIN THREAD of your application unless it is a test
323 // program where latency does not matter. This class is blocking. 324 // program where latency does not matter. This class is blocking.
324 class FileEnumerator { 325 class FileEnumerator {
325 public: 326 public:
327 #if defined(OS_WIN)
328 typedef WIN32_FIND_DATA FindInfo;
329 #elif defined(OS_POSIX)
330 typedef struct {
331 struct stat stat;
332 std::string filename;
333 } FindInfo;
334 #endif
335
326 enum FILE_TYPE { 336 enum FILE_TYPE {
327 FILES = 0x1, 337 FILES = 0x1,
328 DIRECTORIES = 0x2, 338 DIRECTORIES = 0x2,
329 FILES_AND_DIRECTORIES = 0x3 339 FILES_AND_DIRECTORIES = 0x3
330 }; 340 };
331 341
332 // |root_path| is the starting directory to search for. It may or may not end 342 // |root_path| is the starting directory to search for. It may or may not end
333 // in a slash. 343 // in a slash.
334 // 344 //
335 // If |recursive| is true, this will enumerate all matches in any 345 // If |recursive| is true, this will enumerate all matches in any
(...skipping 18 matching lines...) Expand all
354 FileEnumerator::FILE_TYPE file_type); 364 FileEnumerator::FILE_TYPE file_type);
355 FileEnumerator(const std::wstring& root_path, 365 FileEnumerator(const std::wstring& root_path,
356 bool recursive, 366 bool recursive,
357 FileEnumerator::FILE_TYPE file_type, 367 FileEnumerator::FILE_TYPE file_type,
358 const std::wstring& pattern); 368 const std::wstring& pattern);
359 ~FileEnumerator(); 369 ~FileEnumerator();
360 370
361 // Returns an empty string if there are no more results. 371 // Returns an empty string if there are no more results.
362 std::wstring Next(); 372 std::wstring Next();
363 373
374 // Write the file info into |info|.
375 void GetFindInfo(FindInfo* info);
376
364 private: 377 private:
365 std::wstring root_path_; 378 std::wstring root_path_;
366 bool recursive_; 379 bool recursive_;
367 FILE_TYPE file_type_; 380 FILE_TYPE file_type_;
368 std::wstring pattern_; // Empty when we want to find everything. 381 std::wstring pattern_; // Empty when we want to find everything.
369 382
370 // Set to true when there is a find operation open. This way, we can lazily 383 // Set to true when there is a find operation open. This way, we can lazily
371 // start the operations when the caller calls Next(). 384 // start the operations when the caller calls Next().
372 bool is_in_find_op_; 385 bool is_in_find_op_;
373 386
374 // A stack that keeps track of which subdirectories we still need to 387 // A stack that keeps track of which subdirectories we still need to
375 // enumerate in the breadth-first search. 388 // enumerate in the breadth-first search.
376 std::stack<std::wstring> pending_paths_; 389 std::stack<std::wstring> pending_paths_;
377 390
378 #if defined(OS_WIN) 391 #if defined(OS_WIN)
379 WIN32_FIND_DATA find_data_; 392 WIN32_FIND_DATA find_data_;
380 HANDLE find_handle_; 393 HANDLE find_handle_;
381 #elif defined(OS_POSIX) 394 #elif defined(OS_POSIX)
382 FTS* fts_; 395 FTS* fts_;
396 FTSENT* fts_ent_;
383 #endif 397 #endif
384 398
385 DISALLOW_EVIL_CONSTRUCTORS(FileEnumerator); 399 DISALLOW_EVIL_CONSTRUCTORS(FileEnumerator);
386 }; 400 };
387 401
388 // Renames a file using the SHFileOperation API to ensure that the target file 402 // Renames a file using the SHFileOperation API to ensure that the target file
389 // gets the correct default security descriptor in the new path. 403 // gets the correct default security descriptor in the new path.
390 bool RenameFileAndResetSecurityDescriptor( 404 bool RenameFileAndResetSecurityDescriptor(
391 const std::wstring& source_file_path, 405 const std::wstring& source_file_path,
392 const std::wstring& target_file_path); 406 const std::wstring& target_file_path);
393 407
394 } // namespace file_util 408 } // namespace file_util
395 409
396 #endif // BASE_FILE_UTIL_H_ 410 #endif // BASE_FILE_UTIL_H_
OLDNEW
« no previous file with comments | « no previous file | base/file_util_posix.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698