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

Side by Side Diff: base/file_util.h

Issue 18383003: Move DeleteAfterReboot and Move 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 | « no previous file | base/file_util.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 // 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 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 // Returns true if successful, false otherwise. It is considered successful 64 // Returns true if successful, false otherwise. It is considered successful
65 // to attempt to delete a file that does not exist. 65 // to attempt to delete a file that does not exist.
66 // 66 //
67 // In posix environment and if |path| is a symbolic link, this deletes only 67 // In posix environment and if |path| is a symbolic link, this deletes only
68 // the symlink. (even if the symlink points to a non-existent file) 68 // the symlink. (even if the symlink points to a non-existent file)
69 // 69 //
70 // WARNING: USING THIS WITH recursive==true IS EQUIVALENT 70 // WARNING: USING THIS WITH recursive==true IS EQUIVALENT
71 // TO "rm -rf", SO USE WITH CAUTION. 71 // TO "rm -rf", SO USE WITH CAUTION.
72 BASE_EXPORT bool Delete(const FilePath& path, bool recursive); 72 BASE_EXPORT bool Delete(const FilePath& path, bool recursive);
73 73
74 } // namespace base
75
76 // -----------------------------------------------------------------------------
77
78 namespace file_util {
79
80 #if defined(OS_WIN) 74 #if defined(OS_WIN)
81 // Schedules to delete the given path, whether it's a file or a directory, until 75 // Schedules to delete the given path, whether it's a file or a directory, until
82 // the operating system is restarted. 76 // the operating system is restarted.
83 // Note: 77 // Note:
84 // 1) The file/directory to be deleted should exist in a temp folder. 78 // 1) The file/directory to be deleted should exist in a temp folder.
85 // 2) The directory to be deleted must be empty. 79 // 2) The directory to be deleted must be empty.
86 BASE_EXPORT bool DeleteAfterReboot(const base::FilePath& path); 80 BASE_EXPORT bool DeleteAfterReboot(const FilePath& path);
87 #endif 81 #endif
88 82
89 // Moves the given path, whether it's a file or a directory. 83 // Moves the given path, whether it's a file or a directory.
90 // If a simple rename is not possible, such as in the case where the paths are 84 // If a simple rename is not possible, such as in the case where the paths are
91 // on different volumes, this will attempt to copy and delete. Returns 85 // on different volumes, this will attempt to copy and delete. Returns
92 // true for success. 86 // true for success.
93 // This function fails if either path contains traversal components ('..'). 87 // This function fails if either path contains traversal components ('..').
94 BASE_EXPORT bool Move(const base::FilePath& from_path, 88 BASE_EXPORT bool Move(const FilePath& from_path, const FilePath& to_path);
95 const base::FilePath& to_path);
96 89
97 // Same as Move but allows paths with traversal components. 90 // Same as Move but allows paths with traversal components.
98 // Use only with extreme care. 91 // Use only with extreme care.
99 BASE_EXPORT bool MoveUnsafe(const base::FilePath& from_path, 92 BASE_EXPORT bool MoveUnsafe(const FilePath& from_path,
100 const base::FilePath& to_path); 93 const FilePath& to_path);
101 94
102 // Renames file |from_path| to |to_path|. Both paths must be on the same 95 // Renames file |from_path| to |to_path|. Both paths must be on the same
103 // volume, or the function will fail. Destination file will be created 96 // volume, or the function will fail. Destination file will be created
104 // if it doesn't exist. Prefer this function over Move when dealing with 97 // if it doesn't exist. Prefer this function over Move when dealing with
105 // temporary files. On Windows it preserves attributes of the target file. 98 // temporary files. On Windows it preserves attributes of the target file.
106 // Returns true on success, leaving *error unchanged. 99 // Returns true on success, leaving *error unchanged.
107 // Returns false on failure and sets *error appropriately, if it is non-NULL. 100 // Returns false on failure and sets *error appropriately, if it is non-NULL.
108 BASE_EXPORT bool ReplaceFileAndGetError(const base::FilePath& from_path, 101 BASE_EXPORT bool ReplaceFile(const FilePath& from_path,
109 const base::FilePath& to_path, 102 const FilePath& to_path,
110 base::PlatformFileError* error); 103 PlatformFileError* error);
111 104
112 // Backward-compatible convenience method for the above. 105 } // namespace base
113 BASE_EXPORT bool ReplaceFile(const base::FilePath& from_path, 106
114 const base::FilePath& to_path); 107 // -----------------------------------------------------------------------------
108
109 namespace file_util {
115 110
116 // Copies a single file. Use CopyDirectory to copy directories. 111 // Copies a single file. Use CopyDirectory to copy directories.
117 // This function fails if either path contains traversal components ('..'). 112 // This function fails if either path contains traversal components ('..').
118 BASE_EXPORT bool CopyFile(const base::FilePath& from_path, 113 BASE_EXPORT bool CopyFile(const base::FilePath& from_path,
119 const base::FilePath& to_path); 114 const base::FilePath& to_path);
120 115
121 // Same as CopyFile but allows paths with traversal components. 116 // Same as CopyFile but allows paths with traversal components.
122 // Use only with extreme care. 117 // Use only with extreme care.
123 BASE_EXPORT bool CopyFileUnsafe(const base::FilePath& from_path, 118 BASE_EXPORT bool CopyFileUnsafe(const base::FilePath& from_path,
124 const base::FilePath& to_path); 119 const base::FilePath& to_path);
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
453 448
454 // Attempts determine the FileSystemType for |path|. 449 // Attempts determine the FileSystemType for |path|.
455 // Returns false if |path| doesn't exist. 450 // Returns false if |path| doesn't exist.
456 BASE_EXPORT bool GetFileSystemType(const base::FilePath& path, 451 BASE_EXPORT bool GetFileSystemType(const base::FilePath& path,
457 FileSystemType* type); 452 FileSystemType* type);
458 #endif 453 #endif
459 454
460 } // namespace file_util 455 } // namespace file_util
461 456
462 #endif // BASE_FILE_UTIL_H_ 457 #endif // BASE_FILE_UTIL_H_
OLDNEW
« no previous file with comments | « no previous file | base/file_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698