| 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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 // Get the home directory. This is more complicated than just getenv("HOME") | 205 // Get the home directory. This is more complicated than just getenv("HOME") |
| 206 // as it knows to fall back on getpwent() etc. | 206 // as it knows to fall back on getpwent() etc. |
| 207 // | 207 // |
| 208 // This function is not currently implemented on Windows or Mac because we | 208 // This function is not currently implemented on Windows or Mac because we |
| 209 // don't use it. Generally you would use one of PathService's APP_DATA | 209 // don't use it. Generally you would use one of PathService's APP_DATA |
| 210 // directories on those platforms. If we need it, this could be implemented | 210 // directories on those platforms. If we need it, this could be implemented |
| 211 // there to return the appropriate directory. | 211 // there to return the appropriate directory. |
| 212 BASE_EXPORT FilePath GetHomeDir(); | 212 BASE_EXPORT FilePath GetHomeDir(); |
| 213 #endif // OS_POSIX | 213 #endif // OS_POSIX |
| 214 | 214 |
| 215 // Creates a temporary file. The full path is placed in |path|, and the |
| 216 // function returns true if was successful in creating the file. The file will |
| 217 // be empty and all handles closed after this function returns. |
| 218 BASE_EXPORT bool CreateTemporaryFile(FilePath* path); |
| 219 |
| 220 // Same as CreateTemporaryFile but the file is created in |dir|. |
| 221 BASE_EXPORT bool CreateTemporaryFileInDir(const FilePath& dir, |
| 222 FilePath* temp_file); |
| 223 |
| 224 // Create and open a temporary file. File is opened for read/write. |
| 225 // The full path is placed in |path|. |
| 226 // Returns a handle to the opened file or NULL if an error occurred. |
| 227 BASE_EXPORT FILE* CreateAndOpenTemporaryFile(FilePath* path); |
| 228 |
| 229 // Like above but for shmem files. Only useful for POSIX. |
| 230 // The executable flag says the file needs to support using |
| 231 // mprotect with PROT_EXEC after mapping. |
| 232 BASE_EXPORT FILE* CreateAndOpenTemporaryShmemFile(FilePath* path, |
| 233 bool executable); |
| 234 |
| 235 // Similar to CreateAndOpenTemporaryFile, but the file is created in |dir|. |
| 236 BASE_EXPORT FILE* CreateAndOpenTemporaryFileInDir(const FilePath& dir, |
| 237 FilePath* path); |
| 238 |
| 239 // Create a new directory. If prefix is provided, the new directory name is in |
| 240 // the format of prefixyyyy. |
| 241 // NOTE: prefix is ignored in the POSIX implementation. |
| 242 // If success, return true and output the full path of the directory created. |
| 243 BASE_EXPORT bool CreateNewTempDirectory(const FilePath::StringType& prefix, |
| 244 FilePath* new_temp_path); |
| 245 |
| 246 // Create a directory within another directory. |
| 247 // Extra characters will be appended to |prefix| to ensure that the |
| 248 // new directory does not have the same name as an existing directory. |
| 249 BASE_EXPORT bool CreateTemporaryDirInDir(const FilePath& base_dir, |
| 250 const FilePath::StringType& prefix, |
| 251 FilePath* new_dir); |
| 252 |
| 215 } // namespace base | 253 } // namespace base |
| 216 | 254 |
| 217 // ----------------------------------------------------------------------------- | 255 // ----------------------------------------------------------------------------- |
| 218 | 256 |
| 219 namespace file_util { | 257 namespace file_util { |
| 220 | 258 |
| 221 // Creates a temporary file. The full path is placed in |path|, and the | |
| 222 // function returns true if was successful in creating the file. The file will | |
| 223 // be empty and all handles closed after this function returns. | |
| 224 BASE_EXPORT bool CreateTemporaryFile(base::FilePath* path); | |
| 225 | |
| 226 // Same as CreateTemporaryFile but the file is created in |dir|. | |
| 227 BASE_EXPORT bool CreateTemporaryFileInDir(const base::FilePath& dir, | |
| 228 base::FilePath* temp_file); | |
| 229 | |
| 230 // Create and open a temporary file. File is opened for read/write. | |
| 231 // The full path is placed in |path|. | |
| 232 // Returns a handle to the opened file or NULL if an error occurred. | |
| 233 BASE_EXPORT FILE* CreateAndOpenTemporaryFile(base::FilePath* path); | |
| 234 // Like above but for shmem files. Only useful for POSIX. | |
| 235 // The executable flag says the file needs to support using | |
| 236 // mprotect with PROT_EXEC after mapping. | |
| 237 BASE_EXPORT FILE* CreateAndOpenTemporaryShmemFile(base::FilePath* path, | |
| 238 bool executable); | |
| 239 // Similar to CreateAndOpenTemporaryFile, but the file is created in |dir|. | |
| 240 BASE_EXPORT FILE* CreateAndOpenTemporaryFileInDir(const base::FilePath& dir, | |
| 241 base::FilePath* path); | |
| 242 | |
| 243 // Create a new directory. If prefix is provided, the new directory name is in | |
| 244 // the format of prefixyyyy. | |
| 245 // NOTE: prefix is ignored in the POSIX implementation. | |
| 246 // If success, return true and output the full path of the directory created. | |
| 247 BASE_EXPORT bool CreateNewTempDirectory( | |
| 248 const base::FilePath::StringType& prefix, | |
| 249 base::FilePath* new_temp_path); | |
| 250 | |
| 251 // Create a directory within another directory. | |
| 252 // Extra characters will be appended to |prefix| to ensure that the | |
| 253 // new directory does not have the same name as an existing directory. | |
| 254 BASE_EXPORT bool CreateTemporaryDirInDir( | |
| 255 const base::FilePath& base_dir, | |
| 256 const base::FilePath::StringType& prefix, | |
| 257 base::FilePath* new_dir); | |
| 258 | |
| 259 // Creates a directory, as well as creating any parent directories, if they | 259 // Creates a directory, as well as creating any parent directories, if they |
| 260 // don't exist. Returns 'true' on successful creation, or if the directory | 260 // don't exist. Returns 'true' on successful creation, or if the directory |
| 261 // already exists. The directory is only readable by the current user. | 261 // already exists. The directory is only readable by the current user. |
| 262 // Returns true on success, leaving *error unchanged. | 262 // Returns true on success, leaving *error unchanged. |
| 263 // Returns false on failure and sets *error appropriately, if it is non-NULL. | 263 // Returns false on failure and sets *error appropriately, if it is non-NULL. |
| 264 BASE_EXPORT bool CreateDirectoryAndGetError(const base::FilePath& full_path, | 264 BASE_EXPORT bool CreateDirectoryAndGetError(const base::FilePath& full_path, |
| 265 base::PlatformFileError* error); | 265 base::PlatformFileError* error); |
| 266 | 266 |
| 267 // Backward-compatible convenience method for the above. | 267 // Backward-compatible convenience method for the above. |
| 268 BASE_EXPORT bool CreateDirectory(const base::FilePath& full_path); | 268 BASE_EXPORT bool CreateDirectory(const base::FilePath& full_path); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 467 // This function simulates Move(), but unlike Move() it works across volumes. | 467 // This function simulates Move(), but unlike Move() it works across volumes. |
| 468 // This function is not transactional. | 468 // This function is not transactional. |
| 469 BASE_EXPORT bool CopyAndDeleteDirectory(const FilePath& from_path, | 469 BASE_EXPORT bool CopyAndDeleteDirectory(const FilePath& from_path, |
| 470 const FilePath& to_path); | 470 const FilePath& to_path); |
| 471 #endif // defined(OS_WIN) | 471 #endif // defined(OS_WIN) |
| 472 | 472 |
| 473 } // namespace internal | 473 } // namespace internal |
| 474 } // namespace base | 474 } // namespace base |
| 475 | 475 |
| 476 #endif // BASE_FILE_UTIL_H_ | 476 #endif // BASE_FILE_UTIL_H_ |
| OLD | NEW |