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_FILES_FILE_UTIL_H_ | 8 #ifndef BASE_FILES_FILE_UTIL_H_ |
9 #define BASE_FILES_FILE_UTIL_H_ | 9 #define BASE_FILES_FILE_UTIL_H_ |
10 | 10 |
11 #include "build/build_config.h" | 11 #include <stddef.h> |
12 | 12 #include <stdint.h> |
13 #if defined(OS_WIN) | |
14 #include <windows.h> | |
15 #elif defined(OS_POSIX) | |
16 #include <sys/stat.h> | |
17 #include <unistd.h> | |
18 #endif | |
19 | |
20 #include <stdio.h> | 13 #include <stdio.h> |
21 | 14 |
22 #include <set> | 15 #include <set> |
23 #include <string> | 16 #include <string> |
24 #include <vector> | 17 #include <vector> |
25 | 18 |
26 #include "base/base_export.h" | 19 #include "base/base_export.h" |
27 #include "base/basictypes.h" | |
28 #include "base/files/file.h" | 20 #include "base/files/file.h" |
29 #include "base/files/file_path.h" | 21 #include "base/files/file_path.h" |
30 #include "base/memory/scoped_ptr.h" | 22 #include "base/memory/scoped_ptr.h" |
31 #include "base/strings/string16.h" | 23 #include "base/strings/string16.h" |
| 24 #include "build/build_config.h" |
| 25 |
| 26 #if defined(OS_WIN) |
| 27 #include <windows.h> |
| 28 #elif defined(OS_POSIX) |
| 29 #include <sys/stat.h> |
| 30 #include <unistd.h> |
| 31 #endif |
32 | 32 |
33 #if defined(OS_POSIX) | 33 #if defined(OS_POSIX) |
34 #include "base/file_descriptor_posix.h" | 34 #include "base/file_descriptor_posix.h" |
35 #include "base/logging.h" | 35 #include "base/logging.h" |
36 #include "base/posix/eintr_wrapper.h" | 36 #include "base/posix/eintr_wrapper.h" |
37 #endif | 37 #endif |
38 | 38 |
39 namespace base { | 39 namespace base { |
40 | 40 |
41 class Time; | 41 class Time; |
42 | 42 |
43 //----------------------------------------------------------------------------- | 43 //----------------------------------------------------------------------------- |
44 // Functions that involve filesystem access or modification: | 44 // Functions that involve filesystem access or modification: |
45 | 45 |
46 // Returns an absolute version of a relative path. Returns an empty path on | 46 // Returns an absolute version of a relative path. Returns an empty path on |
47 // error. On POSIX, this function fails if the path does not exist. This | 47 // error. On POSIX, this function fails if the path does not exist. This |
48 // function can result in I/O so it can be slow. | 48 // function can result in I/O so it can be slow. |
49 BASE_EXPORT FilePath MakeAbsoluteFilePath(const FilePath& input); | 49 BASE_EXPORT FilePath MakeAbsoluteFilePath(const FilePath& input); |
50 | 50 |
51 // Returns the total number of bytes used by all the files under |root_path|. | 51 // Returns the total number of bytes used by all the files under |root_path|. |
52 // If the path does not exist the function returns 0. | 52 // If the path does not exist the function returns 0. |
53 // | 53 // |
54 // This function is implemented using the FileEnumerator class so it is not | 54 // This function is implemented using the FileEnumerator class so it is not |
55 // particularly speedy in any platform. | 55 // particularly speedy in any platform. |
56 BASE_EXPORT int64 ComputeDirectorySize(const FilePath& root_path); | 56 BASE_EXPORT int64_t ComputeDirectorySize(const FilePath& root_path); |
57 | 57 |
58 // Deletes the given path, whether it's a file or a directory. | 58 // Deletes the given path, whether it's a file or a directory. |
59 // If it's a directory, it's perfectly happy to delete all of the | 59 // If it's a directory, it's perfectly happy to delete all of the |
60 // directory's contents. Passing true to recursive deletes | 60 // directory's contents. Passing true to recursive deletes |
61 // subdirectories and their contents as well. | 61 // subdirectories and their contents as well. |
62 // Returns true if successful, false otherwise. It is considered successful | 62 // Returns true if successful, false otherwise. It is considered successful |
63 // to attempt to delete a file that does not exist. | 63 // to attempt to delete a file that does not exist. |
64 // | 64 // |
65 // In posix environment and if |path| is a symbolic link, this deletes only | 65 // In posix environment and if |path| is a symbolic link, this deletes only |
66 // the symlink. (even if the symlink points to a non-existent file) | 66 // the symlink. (even if the symlink points to a non-existent file) |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
258 // already exists. The directory is only readable by the current user. | 258 // already exists. The directory is only readable by the current user. |
259 // Returns true on success, leaving *error unchanged. | 259 // Returns true on success, leaving *error unchanged. |
260 // Returns false on failure and sets *error appropriately, if it is non-NULL. | 260 // Returns false on failure and sets *error appropriately, if it is non-NULL. |
261 BASE_EXPORT bool CreateDirectoryAndGetError(const FilePath& full_path, | 261 BASE_EXPORT bool CreateDirectoryAndGetError(const FilePath& full_path, |
262 File::Error* error); | 262 File::Error* error); |
263 | 263 |
264 // Backward-compatible convenience method for the above. | 264 // Backward-compatible convenience method for the above. |
265 BASE_EXPORT bool CreateDirectory(const FilePath& full_path); | 265 BASE_EXPORT bool CreateDirectory(const FilePath& full_path); |
266 | 266 |
267 // Returns the file size. Returns true on success. | 267 // Returns the file size. Returns true on success. |
268 BASE_EXPORT bool GetFileSize(const FilePath& file_path, int64* file_size); | 268 BASE_EXPORT bool GetFileSize(const FilePath& file_path, int64_t* file_size); |
269 | 269 |
270 // Sets |real_path| to |path| with symbolic links and junctions expanded. | 270 // Sets |real_path| to |path| with symbolic links and junctions expanded. |
271 // On windows, make sure the path starts with a lettered drive. | 271 // On windows, make sure the path starts with a lettered drive. |
272 // |path| must reference a file. Function will fail if |path| points to | 272 // |path| must reference a file. Function will fail if |path| points to |
273 // a directory or to a nonexistent path. On windows, this function will | 273 // a directory or to a nonexistent path. On windows, this function will |
274 // fail if |path| is a junction or symlink that points to an empty file, | 274 // fail if |path| is a junction or symlink that points to an empty file, |
275 // or if |real_path| would be longer than MAX_PATH characters. | 275 // or if |real_path| would be longer than MAX_PATH characters. |
276 BASE_EXPORT bool NormalizeFilePath(const FilePath& path, FilePath* real_path); | 276 BASE_EXPORT bool NormalizeFilePath(const FilePath& path, FilePath* real_path); |
277 | 277 |
278 #if defined(OS_WIN) | 278 #if defined(OS_WIN) |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 // This function simulates Move(), but unlike Move() it works across volumes. | 432 // This function simulates Move(), but unlike Move() it works across volumes. |
433 // This function is not transactional. | 433 // This function is not transactional. |
434 BASE_EXPORT bool CopyAndDeleteDirectory(const FilePath& from_path, | 434 BASE_EXPORT bool CopyAndDeleteDirectory(const FilePath& from_path, |
435 const FilePath& to_path); | 435 const FilePath& to_path); |
436 #endif // defined(OS_WIN) | 436 #endif // defined(OS_WIN) |
437 | 437 |
438 } // namespace internal | 438 } // namespace internal |
439 } // namespace base | 439 } // namespace base |
440 | 440 |
441 #endif // BASE_FILES_FILE_UTIL_H_ | 441 #endif // BASE_FILES_FILE_UTIL_H_ |
OLD | NEW |