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 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
204 BASE_EXPORT bool IsDirectoryEmpty(const FilePath& dir_path); | 204 BASE_EXPORT bool IsDirectoryEmpty(const FilePath& dir_path); |
205 | 205 |
206 // Get the temporary directory provided by the system. | 206 // Get the temporary directory provided by the system. |
207 // | 207 // |
208 // WARNING: In general, you should use CreateTemporaryFile variants below | 208 // WARNING: In general, you should use CreateTemporaryFile variants below |
209 // instead of this function. Those variants will ensure that the proper | 209 // instead of this function. Those variants will ensure that the proper |
210 // permissions are set so that other users on the system can't edit them while | 210 // permissions are set so that other users on the system can't edit them while |
211 // they're open (which can lead to security issues). | 211 // they're open (which can lead to security issues). |
212 BASE_EXPORT bool GetTempDir(FilePath* path); | 212 BASE_EXPORT bool GetTempDir(FilePath* path); |
213 | 213 |
214 // Get a temporary directory for shared memory files. The directory may depend | |
215 // on whether the destination is intended for executable files, which in turn | |
216 // depends on how /dev/shmem was mounted. As a result, you must supply whether | |
217 // you intend to create executable shmem segments so this function can find | |
218 // an appropriate location. | |
219 // | |
220 // Only useful on POSIX; redirects to GetTempDir() on Windows. | |
221 BASE_EXPORT bool GetShmemTempDir(bool executable, FilePath* path); | |
222 | |
223 // Get the home directory. This is more complicated than just getenv("HOME") | 214 // Get the home directory. This is more complicated than just getenv("HOME") |
224 // as it knows to fall back on getpwent() etc. | 215 // as it knows to fall back on getpwent() etc. |
225 // | 216 // |
226 // You should not generally call this directly. Instead use DIR_HOME with the | 217 // You should not generally call this directly. Instead use DIR_HOME with the |
227 // path service which will use this function but cache the value. | 218 // path service which will use this function but cache the value. |
228 BASE_EXPORT FilePath GetHomeDir(); | 219 BASE_EXPORT FilePath GetHomeDir(); |
229 | 220 |
230 // Creates a temporary file. The full path is placed in |path|, and the | 221 // Creates a temporary file. The full path is placed in |path|, and the |
231 // function returns true if was successful in creating the file. The file will | 222 // function returns true if was successful in creating the file. The file will |
232 // be empty and all handles closed after this function returns. | 223 // be empty and all handles closed after this function returns. |
233 BASE_EXPORT bool CreateTemporaryFile(FilePath* path); | 224 BASE_EXPORT bool CreateTemporaryFile(FilePath* path); |
234 | 225 |
235 // Same as CreateTemporaryFile but the file is created in |dir|. | 226 // Same as CreateTemporaryFile but the file is created in |dir|. |
236 BASE_EXPORT bool CreateTemporaryFileInDir(const FilePath& dir, | 227 BASE_EXPORT bool CreateTemporaryFileInDir(const FilePath& dir, |
237 FilePath* temp_file); | 228 FilePath* temp_file); |
238 | 229 |
239 // Create and open a temporary file. File is opened for read/write. | 230 // Create and open a temporary file. File is opened for read/write. |
240 // The full path is placed in |path|. | 231 // The full path is placed in |path|. |
241 // Returns a handle to the opened file or NULL if an error occurred. | 232 // Returns a handle to the opened file or NULL if an error occurred. |
242 BASE_EXPORT FILE* CreateAndOpenTemporaryFile(FilePath* path); | 233 BASE_EXPORT FILE* CreateAndOpenTemporaryFile(FilePath* path); |
243 | 234 |
244 // Like above but for shmem files. Only useful for POSIX. | |
245 // The executable flag says the file needs to support using | |
246 // mprotect with PROT_EXEC after mapping. | |
247 BASE_EXPORT FILE* CreateAndOpenTemporaryShmemFile(FilePath* path, | |
248 bool executable); | |
249 | |
250 // Similar to CreateAndOpenTemporaryFile, but the file is created in |dir|. | 235 // Similar to CreateAndOpenTemporaryFile, but the file is created in |dir|. |
251 BASE_EXPORT FILE* CreateAndOpenTemporaryFileInDir(const FilePath& dir, | 236 BASE_EXPORT FILE* CreateAndOpenTemporaryFileInDir(const FilePath& dir, |
252 FilePath* path); | 237 FilePath* path); |
253 | 238 |
254 // Create a new directory. If prefix is provided, the new directory name is in | 239 // Create a new directory. If prefix is provided, the new directory name is in |
255 // the format of prefixyyyy. | 240 // the format of prefixyyyy. |
256 // NOTE: prefix is ignored in the POSIX implementation. | 241 // NOTE: prefix is ignored in the POSIX implementation. |
257 // If success, return true and output the full path of the directory created. | 242 // If success, return true and output the full path of the directory created. |
258 BASE_EXPORT bool CreateNewTempDirectory(const FilePath::StringType& prefix, | 243 BASE_EXPORT bool CreateNewTempDirectory(const FilePath::StringType& prefix, |
259 FilePath* new_temp_path); | 244 FilePath* new_temp_path); |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 FILE_SYSTEM_CGROUP, // cgroup control. | 387 FILE_SYSTEM_CGROUP, // cgroup control. |
403 FILE_SYSTEM_OTHER, // any other value. | 388 FILE_SYSTEM_OTHER, // any other value. |
404 FILE_SYSTEM_TYPE_COUNT | 389 FILE_SYSTEM_TYPE_COUNT |
405 }; | 390 }; |
406 | 391 |
407 // Attempts determine the FileSystemType for |path|. | 392 // Attempts determine the FileSystemType for |path|. |
408 // Returns false if |path| doesn't exist. | 393 // Returns false if |path| doesn't exist. |
409 BASE_EXPORT bool GetFileSystemType(const FilePath& path, FileSystemType* type); | 394 BASE_EXPORT bool GetFileSystemType(const FilePath& path, FileSystemType* type); |
410 #endif | 395 #endif |
411 | 396 |
| 397 #if defined(OS_POSIX) |
| 398 // Get a temporary directory for shared memory files. The directory may depend |
| 399 // on whether the destination is intended for executable files, which in turn |
| 400 // depends on how /dev/shmem was mounted. As a result, you must supply whether |
| 401 // you intend to create executable shmem segments so this function can find |
| 402 // an appropriate location. |
| 403 BASE_EXPORT bool GetShmemTempDir(bool executable, FilePath* path); |
| 404 |
| 405 // Like above but for shmem files. Only useful for POSIX. |
| 406 // The executable flag says the file needs to support using |
| 407 // mprotect with PROT_EXEC after mapping. |
| 408 BASE_EXPORT FILE* CreateAndOpenTemporaryShmemFile(FilePath* path, |
| 409 bool executable); |
| 410 #endif |
| 411 |
412 } // namespace base | 412 } // namespace base |
413 | 413 |
414 // ----------------------------------------------------------------------------- | 414 // ----------------------------------------------------------------------------- |
415 | 415 |
416 namespace file_util { | 416 namespace file_util { |
417 | 417 |
418 // Functor for |ScopedFILE| (below). | 418 // Functor for |ScopedFILE| (below). |
419 struct ScopedFILEClose { | 419 struct ScopedFILEClose { |
420 inline void operator()(FILE* x) const { | 420 inline void operator()(FILE* x) const { |
421 if (x) | 421 if (x) |
(...skipping 27 matching lines...) Expand all Loading... |
449 // This function simulates Move(), but unlike Move() it works across volumes. | 449 // This function simulates Move(), but unlike Move() it works across volumes. |
450 // This function is not transactional. | 450 // This function is not transactional. |
451 BASE_EXPORT bool CopyAndDeleteDirectory(const FilePath& from_path, | 451 BASE_EXPORT bool CopyAndDeleteDirectory(const FilePath& from_path, |
452 const FilePath& to_path); | 452 const FilePath& to_path); |
453 #endif // defined(OS_WIN) | 453 #endif // defined(OS_WIN) |
454 | 454 |
455 } // namespace internal | 455 } // namespace internal |
456 } // namespace base | 456 } // namespace base |
457 | 457 |
458 #endif // BASE_FILE_UTIL_H_ | 458 #endif // BASE_FILE_UTIL_H_ |
OLD | NEW |