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

Side by Side Diff: base/file_util.h

Issue 18332014: Move Copy* into the base namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: windows 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 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 BASE_EXPORT bool DeleteAfterReboot(const FilePath& path); 80 BASE_EXPORT bool DeleteAfterReboot(const FilePath& path);
81 #endif 81 #endif
82 82
83 // 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.
84 // 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
85 // on different volumes, this will attempt to copy and delete. Returns 85 // on different volumes, this will attempt to copy and delete. Returns
86 // true for success. 86 // true for success.
87 // This function fails if either path contains traversal components ('..'). 87 // This function fails if either path contains traversal components ('..').
88 BASE_EXPORT bool Move(const FilePath& from_path, const FilePath& to_path); 88 BASE_EXPORT bool Move(const FilePath& from_path, const FilePath& to_path);
89 89
90 // Same as Move but allows paths with traversal components.
91 // Use only with extreme care.
92 BASE_EXPORT bool MoveUnsafe(const FilePath& from_path,
93 const FilePath& to_path);
94
95 // Renames file |from_path| to |to_path|. Both paths must be on the same 90 // Renames file |from_path| to |to_path|. Both paths must be on the same
96 // volume, or the function will fail. Destination file will be created 91 // volume, or the function will fail. Destination file will be created
97 // if it doesn't exist. Prefer this function over Move when dealing with 92 // if it doesn't exist. Prefer this function over Move when dealing with
98 // temporary files. On Windows it preserves attributes of the target file. 93 // temporary files. On Windows it preserves attributes of the target file.
99 // Returns true on success, leaving *error unchanged. 94 // Returns true on success, leaving *error unchanged.
100 // Returns false on failure and sets *error appropriately, if it is non-NULL. 95 // Returns false on failure and sets *error appropriately, if it is non-NULL.
101 BASE_EXPORT bool ReplaceFile(const FilePath& from_path, 96 BASE_EXPORT bool ReplaceFile(const FilePath& from_path,
102 const FilePath& to_path, 97 const FilePath& to_path,
103 PlatformFileError* error); 98 PlatformFileError* error);
104 99
105 } // namespace base
106
107 // -----------------------------------------------------------------------------
108
109 namespace file_util {
110
111 // Copies a single file. Use CopyDirectory to copy directories. 100 // Copies a single file. Use CopyDirectory to copy directories.
112 // This function fails if either path contains traversal components ('..'). 101 // This function fails if either path contains traversal components ('..').
113 BASE_EXPORT bool CopyFile(const base::FilePath& from_path, 102 BASE_EXPORT bool CopyFile(const FilePath& from_path, const FilePath& to_path);
114 const base::FilePath& to_path);
115
116 // Same as CopyFile but allows paths with traversal components.
117 // Use only with extreme care.
118 BASE_EXPORT bool CopyFileUnsafe(const base::FilePath& from_path,
119 const base::FilePath& to_path);
120 103
121 // Copies the given path, and optionally all subdirectories and their contents 104 // Copies the given path, and optionally all subdirectories and their contents
122 // as well. 105 // as well.
123 // 106 //
124 // If there are files existing under to_path, always overwrite. Returns true 107 // If there are files existing under to_path, always overwrite. Returns true
125 // if successful, false otherwise. Wildcards on the names are not supported. 108 // if successful, false otherwise. Wildcards on the names are not supported.
126 // 109 //
127 // If you only need to copy a file use CopyFile, it's faster. 110 // If you only need to copy a file use CopyFile, it's faster.
128 BASE_EXPORT bool CopyDirectory(const base::FilePath& from_path, 111 BASE_EXPORT bool CopyDirectory(const FilePath& from_path,
129 const base::FilePath& to_path, 112 const FilePath& to_path,
130 bool recursive); 113 bool recursive);
131 114
115 } // namespace base
116
117 // -----------------------------------------------------------------------------
118
119 namespace file_util {
120
132 // Returns true if the given path exists on the local filesystem, 121 // Returns true if the given path exists on the local filesystem,
133 // false otherwise. 122 // false otherwise.
134 BASE_EXPORT bool PathExists(const base::FilePath& path); 123 BASE_EXPORT bool PathExists(const base::FilePath& path);
135 124
136 // Returns true if the given path is writable by the user, false otherwise. 125 // Returns true if the given path is writable by the user, false otherwise.
137 BASE_EXPORT bool PathIsWritable(const base::FilePath& path); 126 BASE_EXPORT bool PathIsWritable(const base::FilePath& path);
138 127
139 // Returns true if the given path exists and is a directory, false otherwise. 128 // Returns true if the given path exists and is a directory, false otherwise.
140 BASE_EXPORT bool DirectoryExists(const base::FilePath& path); 129 BASE_EXPORT bool DirectoryExists(const base::FilePath& path);
141 130
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
195 // bits in |mode|. If |path| is symbolic link, |mode| is the permission of 184 // bits in |mode|. If |path| is symbolic link, |mode| is the permission of
196 // a file which the symlink points to. 185 // a file which the symlink points to.
197 BASE_EXPORT bool GetPosixFilePermissions(const base::FilePath& path, 186 BASE_EXPORT bool GetPosixFilePermissions(const base::FilePath& path,
198 int* mode); 187 int* mode);
199 // Sets the permission of the given |path|. If |path| is symbolic link, sets 188 // Sets the permission of the given |path|. If |path| is symbolic link, sets
200 // the permission of a file which the symlink points to. 189 // the permission of a file which the symlink points to.
201 BASE_EXPORT bool SetPosixFilePermissions(const base::FilePath& path, 190 BASE_EXPORT bool SetPosixFilePermissions(const base::FilePath& path,
202 int mode); 191 int mode);
203 #endif // defined(OS_POSIX) 192 #endif // defined(OS_POSIX)
204 193
205 #if defined(OS_WIN)
206 // Copy from_path to to_path recursively and then delete from_path recursively.
207 // Returns true if all operations succeed.
208 // This function simulates Move(), but unlike Move() it works across volumes.
209 // This fuction is not transactional.
210 BASE_EXPORT bool CopyAndDeleteDirectory(const base::FilePath& from_path,
211 const base::FilePath& to_path);
212 #endif // defined(OS_WIN)
213
214 // Return true if the given directory is empty 194 // Return true if the given directory is empty
215 BASE_EXPORT bool IsDirectoryEmpty(const base::FilePath& dir_path); 195 BASE_EXPORT bool IsDirectoryEmpty(const base::FilePath& dir_path);
216 196
217 // Get the temporary directory provided by the system. 197 // Get the temporary directory provided by the system.
218 // WARNING: DON'T USE THIS. If you want to create a temporary file, use one of 198 // WARNING: DON'T USE THIS. If you want to create a temporary file, use one of
219 // the functions below. 199 // the functions below.
220 BASE_EXPORT bool GetTempDir(base::FilePath* path); 200 BASE_EXPORT bool GetTempDir(base::FilePath* path);
221 // Get a temporary directory for shared memory files. 201 // Get a temporary directory for shared memory files.
222 // Only useful on POSIX; redirects to GetTempDir() on Windows. 202 // Only useful on POSIX; redirects to GetTempDir() on Windows.
223 BASE_EXPORT bool GetShmemTempDir(base::FilePath* path, bool executable); 203 BASE_EXPORT bool GetShmemTempDir(base::FilePath* path, bool executable);
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after
447 }; 427 };
448 428
449 // Attempts determine the FileSystemType for |path|. 429 // Attempts determine the FileSystemType for |path|.
450 // Returns false if |path| doesn't exist. 430 // Returns false if |path| doesn't exist.
451 BASE_EXPORT bool GetFileSystemType(const base::FilePath& path, 431 BASE_EXPORT bool GetFileSystemType(const base::FilePath& path,
452 FileSystemType* type); 432 FileSystemType* type);
453 #endif 433 #endif
454 434
455 } // namespace file_util 435 } // namespace file_util
456 436
437 // Internal --------------------------------------------------------------------
438
439 namespace base {
440 namespace internal {
441
442 // Same as Move but allows paths with traversal components.
443 // Use only with extreme care.
444 BASE_EXPORT bool MoveUnsafe(const FilePath& from_path,
445 const FilePath& to_path);
446
447 // Same as CopyFile but allows paths with traversal components.
448 // Use only with extreme care.
449 BASE_EXPORT bool CopyFileUnsafe(const FilePath& from_path,
450 const FilePath& to_path);
451
452 #if defined(OS_WIN)
453 // Copy from_path to to_path recursively and then delete from_path recursively.
454 // Returns true if all operations succeed.
455 // This function simulates Move(), but unlike Move() it works across volumes.
456 // This fuction is not transactional.
457 BASE_EXPORT bool CopyAndDeleteDirectory(const FilePath& from_path,
458 const FilePath& to_path);
459 #endif // defined(OS_WIN)
460
461 } // namespace internal
462 } // namespace base
463
457 #endif // BASE_FILE_UTIL_H_ 464 #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