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

Side by Side Diff: base/file_util.h

Issue 101143006: Convert base::file_util to use File instead of PlatformFile. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove base:: Created 6 years, 11 months 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
« no previous file with comments | « no previous file | base/file_util.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
11 #include "build/build_config.h" 11 #include "build/build_config.h"
12 12
13 #if defined(OS_WIN) 13 #if defined(OS_WIN)
14 #include <windows.h> 14 #include <windows.h>
15 #elif defined(OS_POSIX) 15 #elif defined(OS_POSIX)
16 #include <sys/stat.h> 16 #include <sys/stat.h>
17 #include <unistd.h> 17 #include <unistd.h>
18 #endif 18 #endif
19 19
20 #include <stdio.h> 20 #include <stdio.h>
21 21
22 #include <set> 22 #include <set>
23 #include <string> 23 #include <string>
24 #include <vector> 24 #include <vector>
25 25
26 #include "base/base_export.h" 26 #include "base/base_export.h"
27 #include "base/basictypes.h" 27 #include "base/basictypes.h"
28 #include "base/files/file.h"
28 #include "base/files/file_path.h" 29 #include "base/files/file_path.h"
29 #include "base/memory/scoped_ptr.h" 30 #include "base/memory/scoped_ptr.h"
30 #include "base/platform_file.h"
31 #include "base/strings/string16.h" 31 #include "base/strings/string16.h"
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
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 BASE_EXPORT bool Move(const FilePath& from_path, const FilePath& to_path); 86 BASE_EXPORT bool Move(const FilePath& from_path, const FilePath& to_path);
87 87
88 // Renames file |from_path| to |to_path|. Both paths must be on the same 88 // Renames file |from_path| to |to_path|. Both paths must be on the same
89 // volume, or the function will fail. Destination file will be created 89 // volume, or the function will fail. Destination file will be created
90 // if it doesn't exist. Prefer this function over Move when dealing with 90 // if it doesn't exist. Prefer this function over Move when dealing with
91 // temporary files. On Windows it preserves attributes of the target file. 91 // temporary files. On Windows it preserves attributes of the target file.
92 // Returns true on success, leaving *error unchanged. 92 // Returns true on success, leaving *error unchanged.
93 // Returns false on failure and sets *error appropriately, if it is non-NULL. 93 // Returns false on failure and sets *error appropriately, if it is non-NULL.
94 BASE_EXPORT bool ReplaceFile(const FilePath& from_path, 94 BASE_EXPORT bool ReplaceFile(const FilePath& from_path,
95 const FilePath& to_path, 95 const FilePath& to_path,
96 PlatformFileError* error); 96 File::Error* error);
97 97
98 // Copies a single file. Use CopyDirectory to copy directories. 98 // Copies a single file. Use CopyDirectory to copy directories.
99 // This function fails if either path contains traversal components ('..'). 99 // This function fails if either path contains traversal components ('..').
100 BASE_EXPORT bool CopyFile(const FilePath& from_path, const FilePath& to_path); 100 BASE_EXPORT bool CopyFile(const FilePath& from_path, const FilePath& to_path);
101 101
102 // Copies the given path, and optionally all subdirectories and their contents 102 // Copies the given path, and optionally all subdirectories and their contents
103 // as well. 103 // as well.
104 // 104 //
105 // If there are files existing under to_path, always overwrite. Returns true 105 // If there are files existing under to_path, always overwrite. Returns true
106 // if successful, false otherwise. Wildcards on the names are not supported. 106 // if successful, false otherwise. Wildcards on the names are not supported.
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
249 BASE_EXPORT bool CreateTemporaryDirInDir(const FilePath& base_dir, 249 BASE_EXPORT bool CreateTemporaryDirInDir(const FilePath& base_dir,
250 const FilePath::StringType& prefix, 250 const FilePath::StringType& prefix,
251 FilePath* new_dir); 251 FilePath* new_dir);
252 252
253 // Creates a directory, as well as creating any parent directories, if they 253 // Creates a directory, as well as creating any parent directories, if they
254 // don't exist. Returns 'true' on successful creation, or if the directory 254 // don't exist. Returns 'true' on successful creation, or if the directory
255 // already exists. The directory is only readable by the current user. 255 // already exists. The directory is only readable by the current user.
256 // Returns true on success, leaving *error unchanged. 256 // Returns true on success, leaving *error unchanged.
257 // Returns false on failure and sets *error appropriately, if it is non-NULL. 257 // Returns false on failure and sets *error appropriately, if it is non-NULL.
258 BASE_EXPORT bool CreateDirectoryAndGetError(const FilePath& full_path, 258 BASE_EXPORT bool CreateDirectoryAndGetError(const FilePath& full_path,
259 PlatformFileError* error); 259 File::Error* error);
260 260
261 // Backward-compatible convenience method for the above. 261 // Backward-compatible convenience method for the above.
262 BASE_EXPORT bool CreateDirectory(const FilePath& full_path); 262 BASE_EXPORT bool CreateDirectory(const FilePath& full_path);
263 263
264 // Returns the file size. Returns true on success. 264 // Returns the file size. Returns true on success.
265 BASE_EXPORT bool GetFileSize(const FilePath& file_path, int64* file_size); 265 BASE_EXPORT bool GetFileSize(const FilePath& file_path, int64* file_size);
266 266
267 // Sets |real_path| to |path| with symbolic links and junctions expanded. 267 // Sets |real_path| to |path| with symbolic links and junctions expanded.
268 // On windows, make sure the path starts with a lettered drive. 268 // On windows, make sure the path starts with a lettered drive.
269 // |path| must reference a file. Function will fail if |path| points to 269 // |path| must reference a file. Function will fail if |path| points to
(...skipping 15 matching lines...) Expand all
285 // Returns false if the path can not be found. Empty files cannot 285 // Returns false if the path can not be found. Empty files cannot
286 // be resolved with this function. 286 // be resolved with this function.
287 BASE_EXPORT bool NormalizeToNativeFilePath(const FilePath& path, 287 BASE_EXPORT bool NormalizeToNativeFilePath(const FilePath& path,
288 FilePath* nt_path); 288 FilePath* nt_path);
289 #endif 289 #endif
290 290
291 // This function will return if the given file is a symlink or not. 291 // This function will return if the given file is a symlink or not.
292 BASE_EXPORT bool IsLink(const FilePath& file_path); 292 BASE_EXPORT bool IsLink(const FilePath& file_path);
293 293
294 // Returns information about the given file path. 294 // Returns information about the given file path.
295 BASE_EXPORT bool GetFileInfo(const FilePath& file_path, PlatformFileInfo* info); 295 BASE_EXPORT bool GetFileInfo(const FilePath& file_path, File::Info* info);
296 296
297 // Sets the time of the last access and the time of the last modification. 297 // Sets the time of the last access and the time of the last modification.
298 BASE_EXPORT bool TouchFile(const FilePath& path, 298 BASE_EXPORT bool TouchFile(const FilePath& path,
299 const Time& last_accessed, 299 const Time& last_accessed,
300 const Time& last_modified); 300 const Time& last_modified);
301 301
302 // Wrapper for fopen-like calls. Returns non-NULL FILE* on success. 302 // Wrapper for fopen-like calls. Returns non-NULL FILE* on success.
303 BASE_EXPORT FILE* OpenFile(const FilePath& filename, const char* mode); 303 BASE_EXPORT FILE* OpenFile(const FilePath& filename, const char* mode);
304 304
305 // Closes file opened by OpenFile. Returns true on success. 305 // Closes file opened by OpenFile. Returns true on success.
306 BASE_EXPORT bool CloseFile(FILE* file); 306 BASE_EXPORT bool CloseFile(FILE* file);
307 307
308 // Truncates an open file to end at the location of the current file pointer. 308 // Truncates an open file to end at the location of the current file pointer.
309 // This is a cross-platform analog to Windows' SetEndOfFile() function. 309 // This is a cross-platform analog to Windows' SetEndOfFile() function.
310 BASE_EXPORT bool TruncateFile(FILE* file); 310 BASE_EXPORT bool TruncateFile(FILE* file);
311 311
312 // Reads the given number of bytes from the file into the buffer. Returns 312 // Reads the given number of bytes from the file into the buffer. Returns
313 // the number of read bytes, or -1 on error. 313 // the number of read bytes, or -1 on error.
314 BASE_EXPORT int ReadFile(const base::FilePath& filename, char* data, int size); 314 BASE_EXPORT int ReadFile(const FilePath& filename, char* data, int size);
315 315
316 } // namespace base 316 } // namespace base
317 317
318 // ----------------------------------------------------------------------------- 318 // -----------------------------------------------------------------------------
319 319
320 namespace file_util { 320 namespace file_util {
321 321
322 // Writes the given buffer into the file, overwriting any data that was 322 // Writes the given buffer into the file, overwriting any data that was
323 // previously there. Returns the number of bytes written, or -1 on error. 323 // previously there. Returns the number of bytes written, or -1 on error.
324 BASE_EXPORT int WriteFile(const base::FilePath& filename, const char* data, 324 BASE_EXPORT int WriteFile(const base::FilePath& filename, const char* data,
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
456 // This function simulates Move(), but unlike Move() it works across volumes. 456 // This function simulates Move(), but unlike Move() it works across volumes.
457 // This function is not transactional. 457 // This function is not transactional.
458 BASE_EXPORT bool CopyAndDeleteDirectory(const FilePath& from_path, 458 BASE_EXPORT bool CopyAndDeleteDirectory(const FilePath& from_path,
459 const FilePath& to_path); 459 const FilePath& to_path);
460 #endif // defined(OS_WIN) 460 #endif // defined(OS_WIN)
461 461
462 } // namespace internal 462 } // namespace internal
463 } // namespace base 463 } // namespace base
464 464
465 #endif // BASE_FILE_UTIL_H_ 465 #endif // BASE_FILE_UTIL_H_
OLDNEW
« no previous file with comments | « no previous file | base/file_util.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698