native_file_util.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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
  3. // found in the LICENSE file.
  4. #ifndef STORAGE_BROWSER_FILE_SYSTEM_NATIVE_FILE_UTIL_H_
  5. #define STORAGE_BROWSER_FILE_SYSTEM_NATIVE_FILE_UTIL_H_
  6. #include <stdint.h>
  7. #include <memory>
  8. #include "base/component_export.h"
  9. #include "base/files/file.h"
  10. #include "base/files/file_path.h"
  11. #include "storage/browser/file_system/file_system_file_util.h"
  12. namespace base {
  13. class Time;
  14. }
  15. namespace storage {
  16. // A thin wrapper class for accessing the OS native filesystem.
  17. // This performs common error checks necessary to implement FileUtil family
  18. // in addition to perform native filesystem operations.
  19. //
  20. // For the error checks it performs please see the comment for
  21. // FileSystemFileUtil interface
  22. // (storage/browser/file_system/file_system_file_util.h).
  23. //
  24. // Note that all the methods of this class are static and this does NOT
  25. // inherit from FileSystemFileUtil.
  26. class COMPONENT_EXPORT(STORAGE_BROWSER) NativeFileUtil {
  27. public:
  28. enum CopyOrMoveMode { COPY_NOSYNC, COPY_SYNC, MOVE };
  29. NativeFileUtil() = delete;
  30. NativeFileUtil(const NativeFileUtil&) = delete;
  31. NativeFileUtil& operator=(const NativeFileUtil&) = delete;
  32. static CopyOrMoveMode CopyOrMoveModeForDestination(
  33. const FileSystemURL& dest_url,
  34. bool copy);
  35. static base::File CreateOrOpen(const base::FilePath& path,
  36. uint32_t file_flags);
  37. static base::File::Error EnsureFileExists(const base::FilePath& path,
  38. bool* created);
  39. static base::File::Error CreateDirectory(const base::FilePath& path,
  40. bool exclusive,
  41. bool recursive);
  42. static base::File::Error GetFileInfo(const base::FilePath& path,
  43. base::File::Info* file_info);
  44. static std::unique_ptr<FileSystemFileUtil::AbstractFileEnumerator>
  45. CreateFileEnumerator(const base::FilePath& root_path, bool recursive);
  46. static base::File::Error Touch(const base::FilePath& path,
  47. const base::Time& last_access_time,
  48. const base::Time& last_modified_time);
  49. static base::File::Error Truncate(const base::FilePath& path, int64_t length);
  50. static bool PathExists(const base::FilePath& path);
  51. static bool DirectoryExists(const base::FilePath& path);
  52. static base::File::Error CopyOrMoveFile(
  53. const base::FilePath& src_path,
  54. const base::FilePath& dest_path,
  55. FileSystemOperation::CopyOrMoveOptionSet options,
  56. CopyOrMoveMode mode);
  57. static base::File::Error DeleteFile(const base::FilePath& path);
  58. static base::File::Error DeleteDirectory(const base::FilePath& path);
  59. };
  60. } // namespace storage
  61. #endif // STORAGE_BROWSER_FILE_SYSTEM_NATIVE_FILE_UTIL_H_