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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 // | 109 // |
110 // 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. |
111 BASE_EXPORT bool CopyDirectory(const FilePath& from_path, | 111 BASE_EXPORT bool CopyDirectory(const FilePath& from_path, |
112 const FilePath& to_path, | 112 const FilePath& to_path, |
113 bool recursive); | 113 bool recursive); |
114 | 114 |
115 // Returns true if the given path exists on the local filesystem, | 115 // Returns true if the given path exists on the local filesystem, |
116 // false otherwise. | 116 // false otherwise. |
117 BASE_EXPORT bool PathExists(const FilePath& path); | 117 BASE_EXPORT bool PathExists(const FilePath& path); |
118 | 118 |
| 119 // Returns true if the given path is writable by the user, false otherwise. |
| 120 BASE_EXPORT bool PathIsWritable(const FilePath& path); |
| 121 |
| 122 // Returns true if the given path exists and is a directory, false otherwise. |
| 123 BASE_EXPORT bool DirectoryExists(const FilePath& path); |
| 124 |
| 125 // Returns true if the contents of the two files given are equal, false |
| 126 // otherwise. If either file can't be read, returns false. |
| 127 BASE_EXPORT bool ContentsEqual(const FilePath& filename1, |
| 128 const FilePath& filename2); |
| 129 |
| 130 // Returns true if the contents of the two text files given are equal, false |
| 131 // otherwise. This routine treats "\r\n" and "\n" as equivalent. |
| 132 BASE_EXPORT bool TextContentsEqual(const FilePath& filename1, |
| 133 const FilePath& filename2); |
| 134 |
119 } // namespace base | 135 } // namespace base |
120 | 136 |
121 // ----------------------------------------------------------------------------- | 137 // ----------------------------------------------------------------------------- |
122 | 138 |
123 namespace file_util { | 139 namespace file_util { |
124 | 140 |
125 // Returns true if the given path is writable by the user, false otherwise. | |
126 BASE_EXPORT bool PathIsWritable(const base::FilePath& path); | |
127 | |
128 // Returns true if the given path exists and is a directory, false otherwise. | |
129 BASE_EXPORT bool DirectoryExists(const base::FilePath& path); | |
130 | |
131 // Returns true if the contents of the two files given are equal, false | |
132 // otherwise. If either file can't be read, returns false. | |
133 BASE_EXPORT bool ContentsEqual(const base::FilePath& filename1, | |
134 const base::FilePath& filename2); | |
135 | |
136 // Returns true if the contents of the two text files given are equal, false | |
137 // otherwise. This routine treats "\r\n" and "\n" as equivalent. | |
138 BASE_EXPORT bool TextContentsEqual(const base::FilePath& filename1, | |
139 const base::FilePath& filename2); | |
140 | |
141 // Read the file at |path| into |contents|, returning true on success. | 141 // Read the file at |path| into |contents|, returning true on success. |
142 // This function fails if the |path| contains path traversal components ('..'). | 142 // This function fails if the |path| contains path traversal components ('..'). |
143 // |contents| may be NULL, in which case this function is useful for its | 143 // |contents| may be NULL, in which case this function is useful for its |
144 // side effect of priming the disk cache. | 144 // side effect of priming the disk cache. |
145 // Useful for unit tests. | 145 // Useful for unit tests. |
146 BASE_EXPORT bool ReadFileToString(const base::FilePath& path, | 146 BASE_EXPORT bool ReadFileToString(const base::FilePath& path, |
147 std::string* contents); | 147 std::string* contents); |
148 | 148 |
149 #if defined(OS_POSIX) | 149 #if defined(OS_POSIX) |
150 // Read exactly |bytes| bytes from file descriptor |fd|, storing the result | 150 // Read exactly |bytes| bytes from file descriptor |fd|, storing the result |
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
455 // This function simulates Move(), but unlike Move() it works across volumes. | 455 // This function simulates Move(), but unlike Move() it works across volumes. |
456 // This fuction is not transactional. | 456 // This fuction is not transactional. |
457 BASE_EXPORT bool CopyAndDeleteDirectory(const FilePath& from_path, | 457 BASE_EXPORT bool CopyAndDeleteDirectory(const FilePath& from_path, |
458 const FilePath& to_path); | 458 const FilePath& to_path); |
459 #endif // defined(OS_WIN) | 459 #endif // defined(OS_WIN) |
460 | 460 |
461 } // namespace internal | 461 } // namespace internal |
462 } // namespace base | 462 } // namespace base |
463 | 463 |
464 #endif // BASE_FILE_UTIL_H_ | 464 #endif // BASE_FILE_UTIL_H_ |
OLD | NEW |