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 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 // Note: | 113 // Note: |
114 // 1) The file/directory to be deleted should exist in a temp folder. | 114 // 1) The file/directory to be deleted should exist in a temp folder. |
115 // 2) The directory to be deleted must be empty. | 115 // 2) The directory to be deleted must be empty. |
116 BASE_EXPORT bool DeleteAfterReboot(const base::FilePath& path); | 116 BASE_EXPORT bool DeleteAfterReboot(const base::FilePath& path); |
117 #endif | 117 #endif |
118 | 118 |
119 // Moves the given path, whether it's a file or a directory. | 119 // Moves the given path, whether it's a file or a directory. |
120 // If a simple rename is not possible, such as in the case where the paths are | 120 // If a simple rename is not possible, such as in the case where the paths are |
121 // on different volumes, this will attempt to copy and delete. Returns | 121 // on different volumes, this will attempt to copy and delete. Returns |
122 // true for success. | 122 // true for success. |
| 123 // This function fails if either path contains traversal components ('..'). |
123 BASE_EXPORT bool Move(const base::FilePath& from_path, | 124 BASE_EXPORT bool Move(const base::FilePath& from_path, |
124 const base::FilePath& to_path); | 125 const base::FilePath& to_path); |
125 | 126 |
| 127 // Same as Move but allows paths with traversal components. |
| 128 // Use only with extreme care. |
| 129 BASE_EXPORT bool MoveUnsafe(const base::FilePath& from_path, |
| 130 const base::FilePath& to_path); |
| 131 |
126 // Renames file |from_path| to |to_path|. Both paths must be on the same | 132 // Renames file |from_path| to |to_path|. Both paths must be on the same |
127 // volume, or the function will fail. Destination file will be created | 133 // volume, or the function will fail. Destination file will be created |
128 // if it doesn't exist. Prefer this function over Move when dealing with | 134 // if it doesn't exist. Prefer this function over Move when dealing with |
129 // temporary files. On Windows it preserves attributes of the target file. | 135 // temporary files. On Windows it preserves attributes of the target file. |
130 // Returns true on success. | 136 // Returns true on success. |
131 BASE_EXPORT bool ReplaceFile(const base::FilePath& from_path, | 137 BASE_EXPORT bool ReplaceFile(const base::FilePath& from_path, |
132 const base::FilePath& to_path); | 138 const base::FilePath& to_path); |
133 | 139 |
134 // Copies a single file. Use CopyDirectory to copy directories. | 140 // Copies a single file. Use CopyDirectory to copy directories. |
| 141 // This function fails if either path contains traversal components ('..'). |
135 BASE_EXPORT bool CopyFile(const base::FilePath& from_path, | 142 BASE_EXPORT bool CopyFile(const base::FilePath& from_path, |
136 const base::FilePath& to_path); | 143 const base::FilePath& to_path); |
137 | 144 |
| 145 // Same as CopyFile but allows paths with traversal components. |
| 146 // Use only with extreme care. |
| 147 BASE_EXPORT bool CopyFileUnsafe(const base::FilePath& from_path, |
| 148 const base::FilePath& to_path); |
| 149 |
138 // Copies the given path, and optionally all subdirectories and their contents | 150 // Copies the given path, and optionally all subdirectories and their contents |
139 // as well. | 151 // as well. |
140 // If there are files existing under to_path, always overwrite. | 152 // If there are files existing under to_path, always overwrite. |
141 // Returns true if successful, false otherwise. | 153 // Returns true if successful, false otherwise. |
142 // Don't use wildcards on the names, it may stop working without notice. | 154 // Don't use wildcards on the names, it may stop working without notice. |
143 // | 155 // |
144 // If you only need to copy a file use CopyFile, it's faster. | 156 // If you only need to copy a file use CopyFile, it's faster. |
145 BASE_EXPORT bool CopyDirectory(const base::FilePath& from_path, | 157 BASE_EXPORT bool CopyDirectory(const base::FilePath& from_path, |
146 const base::FilePath& to_path, | 158 const base::FilePath& to_path, |
147 bool recursive); | 159 bool recursive); |
(...skipping 471 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
619 | 631 |
620 // Attempts determine the FileSystemType for |path|. | 632 // Attempts determine the FileSystemType for |path|. |
621 // Returns false if |path| doesn't exist. | 633 // Returns false if |path| doesn't exist. |
622 BASE_EXPORT bool GetFileSystemType(const base::FilePath& path, | 634 BASE_EXPORT bool GetFileSystemType(const base::FilePath& path, |
623 FileSystemType* type); | 635 FileSystemType* type); |
624 #endif | 636 #endif |
625 | 637 |
626 } // namespace file_util | 638 } // namespace file_util |
627 | 639 |
628 #endif // BASE_FILE_UTIL_H_ | 640 #endif // BASE_FILE_UTIL_H_ |
OLD | NEW |