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

Side by Side Diff: base/file_util.h

Issue 5754002: Moving away from shell api to support long path names on windows for filesystem. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 10 years 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
OLDNEW
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2010 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 #pragma once 10 #pragma once
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 const FilePath::StringType& pattern); 93 const FilePath::StringType& pattern);
94 94
95 // Deletes the given path, whether it's a file or a directory. 95 // Deletes the given path, whether it's a file or a directory.
96 // If it's a directory, it's perfectly happy to delete all of the 96 // If it's a directory, it's perfectly happy to delete all of the
97 // directory's contents. Passing true to recursive deletes 97 // directory's contents. Passing true to recursive deletes
98 // subdirectories and their contents as well. 98 // subdirectories and their contents as well.
99 // Returns true if successful, false otherwise. 99 // Returns true if successful, false otherwise.
100 // 100 //
101 // WARNING: USING THIS WITH recursive==true IS EQUIVALENT 101 // WARNING: USING THIS WITH recursive==true IS EQUIVALENT
102 // TO "rm -rf", SO USE WITH CAUTION. 102 // TO "rm -rf", SO USE WITH CAUTION.
103 // Safe to pass extended-path to this method on Windows.
Erik does not do reviews 2010/12/23 17:57:27 It seems better to mark all of the ones that are u
103 bool Delete(const FilePath& path, bool recursive); 104 bool Delete(const FilePath& path, bool recursive);
104 105
105 #if defined(OS_WIN) 106 #if defined(OS_WIN)
106 // Schedules to delete the given path, whether it's a file or a directory, until 107 // Schedules to delete the given path, whether it's a file or a directory, until
107 // the operating system is restarted. 108 // the operating system is restarted.
108 // Note: 109 // Note:
109 // 1) The file/directory to be deleted should exist in a temp folder. 110 // 1) The file/directory to be deleted should exist in a temp folder.
110 // 2) The directory to be deleted must be empty. 111 // 2) The directory to be deleted must be empty.
111 bool DeleteAfterReboot(const FilePath& path); 112 bool DeleteAfterReboot(const FilePath& path);
112 #endif 113 #endif
113 114
114 // Moves the given path, whether it's a file or a directory. 115 // Moves the given path, whether it's a file or a directory.
115 // If a simple rename is not possible, such as in the case where the paths are 116 // If a simple rename is not possible, such as in the case where the paths are
116 // on different volumes, this will attempt to copy and delete. Returns 117 // on different volumes, this will attempt to copy and delete. Returns
117 // true for success. 118 // true for success.
119 // Safe to pass extended paths on Windows.
118 bool Move(const FilePath& from_path, const FilePath& to_path); 120 bool Move(const FilePath& from_path, const FilePath& to_path);
119 121
120 // Renames file |from_path| to |to_path|. Both paths must be on the same 122 // Renames file |from_path| to |to_path|. Both paths must be on the same
121 // volume, or the function will fail. Destination file will be created 123 // volume, or the function will fail. Destination file will be created
122 // if it doesn't exist. Prefer this function over Move when dealing with 124 // if it doesn't exist. Prefer this function over Move when dealing with
123 // temporary files. On Windows it preserves attributes of the target file. 125 // temporary files. On Windows it preserves attributes of the target file.
124 // Returns true on success. 126 // Returns true on success.
125 bool ReplaceFile(const FilePath& from_path, const FilePath& to_path); 127 bool ReplaceFile(const FilePath& from_path, const FilePath& to_path);
126 128
127 // Copies a single file. Use CopyDirectory to copy directories. 129 // Copies a single file. Use CopyDirectory to copy directories.
130 // Safe to pass extended-path to this method on Windows.
128 bool CopyFile(const FilePath& from_path, const FilePath& to_path); 131 bool CopyFile(const FilePath& from_path, const FilePath& to_path);
129 132
130 // Copies the given path, and optionally all subdirectories and their contents 133 // Copies the given path, and optionally all subdirectories and their contents
131 // as well. 134 // as well.
132 // If there are files existing under to_path, always overwrite. 135 // If there are files existing under to_path, always overwrite.
133 // Returns true if successful, false otherwise. 136 // Returns true if successful, false otherwise.
134 // Don't use wildcards on the names, it may stop working without notice. 137 // Don't use wildcards on the names, it may stop working without notice.
135 // 138 //
136 // If you only need to copy a file use CopyFile, it's faster. 139 // If you only need to copy a file use CopyFile, it's faster.
140 // Safe to pass extended-path to this method on Windows.
137 bool CopyDirectory(const FilePath& from_path, const FilePath& to_path, 141 bool CopyDirectory(const FilePath& from_path, const FilePath& to_path,
138 bool recursive); 142 bool recursive);
139 143
140 // Returns true if the given path exists on the local filesystem, 144 // Returns true if the given path exists on the local filesystem,
141 // false otherwise. 145 // false otherwise.
146 // Safe to use extended path on Windows.
142 bool PathExists(const FilePath& path); 147 bool PathExists(const FilePath& path);
143 148
144 // Returns true if the given path is writable by the user, false otherwise. 149 // Returns true if the given path is writable by the user, false otherwise.
145 bool PathIsWritable(const FilePath& path); 150 bool PathIsWritable(const FilePath& path);
146 151
147 // Returns true if the given path exists and is a directory, false otherwise. 152 // Returns true if the given path exists and is a directory, false otherwise.
153 // Safe to use extended path on Windows.
148 bool DirectoryExists(const FilePath& path); 154 bool DirectoryExists(const FilePath& path);
149 155
150 #if defined(OS_WIN) 156 #if defined(OS_WIN)
151 // Gets the creation time of the given file (expressed in the local timezone), 157 // Gets the creation time of the given file (expressed in the local timezone),
152 // and returns it via the creation_time parameter. Returns true if successful, 158 // and returns it via the creation_time parameter. Returns true if successful,
153 // false otherwise. 159 // false otherwise.
154 bool GetFileCreationLocalTime(const std::wstring& filename, 160 bool GetFileCreationLocalTime(const std::wstring& filename,
155 LPSYSTEMTIME creation_time); 161 LPSYSTEMTIME creation_time);
156 162
157 // Same as above, but takes a previously-opened file handle instead of a name. 163 // Same as above, but takes a previously-opened file handle instead of a name.
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 bool TaskbarUnpinShortcutLink(const wchar_t* shortcut); 237 bool TaskbarUnpinShortcutLink(const wchar_t* shortcut);
232 238
233 // Copy from_path to to_path recursively and then delete from_path recursively. 239 // Copy from_path to to_path recursively and then delete from_path recursively.
234 // Returns true if all operations succeed. 240 // Returns true if all operations succeed.
235 // This function simulates Move(), but unlike Move() it works across volumes. 241 // This function simulates Move(), but unlike Move() it works across volumes.
236 // This fuction is not transactional. 242 // This fuction is not transactional.
237 bool CopyAndDeleteDirectory(const FilePath& from_path, 243 bool CopyAndDeleteDirectory(const FilePath& from_path,
238 const FilePath& to_path); 244 const FilePath& to_path);
239 #endif // defined(OS_WIN) 245 #endif // defined(OS_WIN)
240 246
241 // Return true if the given directory is empty 247 // Return true if the given directory is empty.
248 // Safe to pass extended-path to this method on Windows.
242 bool IsDirectoryEmpty(const FilePath& dir_path); 249 bool IsDirectoryEmpty(const FilePath& dir_path);
243 250
244 // Get the temporary directory provided by the system. 251 // Get the temporary directory provided by the system.
245 // WARNING: DON'T USE THIS. If you want to create a temporary file, use one of 252 // WARNING: DON'T USE THIS. If you want to create a temporary file, use one of
246 // the functions below. 253 // the functions below.
247 bool GetTempDir(FilePath* path); 254 bool GetTempDir(FilePath* path);
248 // Get a temporary directory for shared memory files. 255 // Get a temporary directory for shared memory files.
249 // Only useful on POSIX; redirects to GetTempDir() on Windows. 256 // Only useful on POSIX; redirects to GetTempDir() on Windows.
250 bool GetShmemTempDir(FilePath* path); 257 bool GetShmemTempDir(FilePath* path);
251 258
(...skipping 28 matching lines...) Expand all
280 // Create a directory within another directory. 287 // Create a directory within another directory.
281 // Extra characters will be appended to |prefix| to ensure that the 288 // Extra characters will be appended to |prefix| to ensure that the
282 // new directory does not have the same name as an existing directory. 289 // new directory does not have the same name as an existing directory.
283 bool CreateTemporaryDirInDir(const FilePath& base_dir, 290 bool CreateTemporaryDirInDir(const FilePath& base_dir,
284 const FilePath::StringType& prefix, 291 const FilePath::StringType& prefix,
285 FilePath* new_dir); 292 FilePath* new_dir);
286 293
287 // Creates a directory, as well as creating any parent directories, if they 294 // Creates a directory, as well as creating any parent directories, if they
288 // don't exist. Returns 'true' on successful creation, or if the directory 295 // don't exist. Returns 'true' on successful creation, or if the directory
289 // already exists. The directory is only readable by the current user. 296 // already exists. The directory is only readable by the current user.
297 // Safe to pass extended path on Windows.
290 bool CreateDirectory(const FilePath& full_path); 298 bool CreateDirectory(const FilePath& full_path);
291 299
292 // Returns the file size. Returns true on success. 300 // Returns the file size. Returns true on success.
293 bool GetFileSize(const FilePath& file_path, int64* file_size); 301 bool GetFileSize(const FilePath& file_path, int64* file_size);
294 302
295 // Returns true if the given path's base name is ".". 303 // Returns true if the given path's base name is ".".
296 bool IsDot(const FilePath& path); 304 bool IsDot(const FilePath& path);
297 305
298 // Returns true if the given path's base name is "..". 306 // Returns true if the given path's base name is "..".
299 bool IsDotDot(const FilePath& path); 307 bool IsDotDot(const FilePath& path);
300 308
301 // Sets |real_path| to |path| with symbolic links and junctions expanded. 309 // Sets |real_path| to |path| with symbolic links and junctions expanded.
302 // On windows, make sure the path starts with a lettered drive. 310 // On windows, make sure the path starts with a lettered drive.
303 // |path| must reference a file. Function will fail if |path| points to 311 // |path| must reference a file. Function will fail if |path| points to
304 // a directory or to a nonexistent path. On windows, this function will 312 // a directory or to a nonexistent path. On windows, this function will
305 // fail if |path| is a junction or symlink that points to an empty file, 313 // fail if |path| is a junction or symlink that points to an empty file,
306 // or if |real_path| would be longer than MAX_PATH characters. 314 // or if |real_path| would be longer than MAX_PATH characters.
307 bool NormalizeFilePath(const FilePath& path, FilePath* real_path); 315 bool NormalizeFilePath(const FilePath& path, FilePath* real_path);
308 316
309 #if defined(OS_WIN) 317 #if defined(OS_WIN)
310 // Given an existing file in |path|, it returns in |real_path| the path 318 // Given an existing file in |path|, it returns in |real_path| the path
311 // in the native NT format, of the form "\Device\HarddiskVolumeXX\..". 319 // in the native NT format, of the form "\Device\HarddiskVolumeXX\..".
312 // Returns false it it fails. Empty files cannot be resolved with this 320 // Returns false it it fails. Empty files cannot be resolved with this
313 // function. 321 // function.
314 bool NormalizeToNativeFilePath(const FilePath& path, FilePath* nt_path); 322 bool NormalizeToNativeFilePath(const FilePath& path, FilePath* nt_path);
315 #endif 323 #endif
316 324
317 // Returns information about the given file path. 325 // Returns information about the given file path.
326 // Safe to use extended path on Windows.
318 bool GetFileInfo(const FilePath& file_path, base::PlatformFileInfo* info); 327 bool GetFileInfo(const FilePath& file_path, base::PlatformFileInfo* info);
319 328
320 // Sets the time of the last access and the time of the last modification. 329 // Sets the time of the last access and the time of the last modification.
321 bool TouchFile(const FilePath& path, 330 bool TouchFile(const FilePath& path,
322 const base::Time& last_accessed, 331 const base::Time& last_accessed,
323 const base::Time& last_modified); 332 const base::Time& last_modified);
324 333
325 // Set the time of the last modification. Useful for unit tests. 334 // Set the time of the last modification. Useful for unit tests.
326 bool SetLastModifiedTime(const FilePath& path, 335 bool SetLastModifiedTime(const FilePath& path,
327 const base::Time& last_modified); 336 const base::Time& last_modified);
(...skipping 296 matching lines...) Expand 10 before | Expand all | Expand 10 after
624 bool GetFileSystemType(const FilePath& path, FileSystemType* type); 633 bool GetFileSystemType(const FilePath& path, FileSystemType* type);
625 #endif 634 #endif
626 635
627 } // namespace file_util 636 } // namespace file_util
628 637
629 // Deprecated functions have been moved to this separate header file, 638 // Deprecated functions have been moved to this separate header file,
630 // which must be included last after all the above definitions. 639 // which must be included last after all the above definitions.
631 #include "base/file_util_deprecated.h" 640 #include "base/file_util_deprecated.h"
632 641
633 #endif // BASE_FILE_UTIL_H_ 642 #endif // BASE_FILE_UTIL_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698