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 // 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 392 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
403 | 403 |
404 #if defined(OS_POSIX) | 404 #if defined(OS_POSIX) |
405 // Get a temporary directory for shared memory files. The directory may depend | 405 // Get a temporary directory for shared memory files. The directory may depend |
406 // on whether the destination is intended for executable files, which in turn | 406 // on whether the destination is intended for executable files, which in turn |
407 // depends on how /dev/shmem was mounted. As a result, you must supply whether | 407 // depends on how /dev/shmem was mounted. As a result, you must supply whether |
408 // you intend to create executable shmem segments so this function can find | 408 // you intend to create executable shmem segments so this function can find |
409 // an appropriate location. | 409 // an appropriate location. |
410 BASE_EXPORT bool GetShmemTempDir(bool executable, FilePath* path); | 410 BASE_EXPORT bool GetShmemTempDir(bool executable, FilePath* path); |
411 #endif | 411 #endif |
412 | 412 |
413 } // namespace base | |
414 | |
415 // ----------------------------------------------------------------------------- | |
416 | |
417 namespace file_util { | |
418 | |
419 // Functor for |ScopedFILE| (below). | |
420 struct ScopedFILEClose { | |
421 inline void operator()(FILE* x) const { | |
422 if (x) | |
423 fclose(x); | |
424 } | |
425 }; | |
426 | |
427 // Automatically closes |FILE*|s. | |
428 typedef scoped_ptr<FILE, ScopedFILEClose> ScopedFILE; | |
429 | |
430 } // namespace file_util | |
431 | |
432 // Internal -------------------------------------------------------------------- | 413 // Internal -------------------------------------------------------------------- |
433 | 414 |
434 namespace base { | |
435 namespace internal { | 415 namespace internal { |
436 | 416 |
437 // Same as Move but allows paths with traversal components. | 417 // Same as Move but allows paths with traversal components. |
438 // Use only with extreme care. | 418 // Use only with extreme care. |
439 BASE_EXPORT bool MoveUnsafe(const FilePath& from_path, | 419 BASE_EXPORT bool MoveUnsafe(const FilePath& from_path, |
440 const FilePath& to_path); | 420 const FilePath& to_path); |
441 | 421 |
442 // Same as CopyFile but allows paths with traversal components. | 422 // Same as CopyFile but allows paths with traversal components. |
443 // Use only with extreme care. | 423 // Use only with extreme care. |
444 BASE_EXPORT bool CopyFileUnsafe(const FilePath& from_path, | 424 BASE_EXPORT bool CopyFileUnsafe(const FilePath& from_path, |
445 const FilePath& to_path); | 425 const FilePath& to_path); |
446 | 426 |
447 #if defined(OS_WIN) | 427 #if defined(OS_WIN) |
448 // Copy from_path to to_path recursively and then delete from_path recursively. | 428 // Copy from_path to to_path recursively and then delete from_path recursively. |
449 // Returns true if all operations succeed. | 429 // Returns true if all operations succeed. |
450 // This function simulates Move(), but unlike Move() it works across volumes. | 430 // This function simulates Move(), but unlike Move() it works across volumes. |
451 // This function is not transactional. | 431 // This function is not transactional. |
452 BASE_EXPORT bool CopyAndDeleteDirectory(const FilePath& from_path, | 432 BASE_EXPORT bool CopyAndDeleteDirectory(const FilePath& from_path, |
453 const FilePath& to_path); | 433 const FilePath& to_path); |
454 #endif // defined(OS_WIN) | 434 #endif // defined(OS_WIN) |
455 | 435 |
456 } // namespace internal | 436 } // namespace internal |
457 } // namespace base | 437 } // namespace base |
458 | 438 |
459 #endif // BASE_FILE_UTIL_H_ | 439 #endif // BASE_FILE_UTIL_H_ |
OLD | NEW |