• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2013 The Flutter 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 
5 #ifndef FLUTTER_FML_FILE_H_
6 #define FLUTTER_FML_FILE_H_
7 
8 #include <initializer_list>
9 #include <string>
10 #include <vector>
11 
12 #include "flutter/fml/macros.h"
13 #include "flutter/fml/unique_fd.h"
14 
15 #ifdef ERROR
16 #undef ERROR
17 #endif
18 
19 namespace fml {
20 
21 class Mapping;
22 
23 enum class FilePermission {
24   kRead,
25   kWrite,
26   kReadWrite,
27 };
28 
29 std::string CreateTemporaryDirectory();
30 
31 fml::UniqueFD OpenFile(const char* path,
32                        bool create_if_necessary,
33                        FilePermission permission);
34 
35 fml::UniqueFD OpenFile(const fml::UniqueFD& base_directory,
36                        const char* path,
37                        bool create_if_necessary,
38                        FilePermission permission);
39 
40 fml::UniqueFD OpenDirectory(const char* path,
41                             bool create_if_necessary,
42                             FilePermission permission);
43 
44 fml::UniqueFD OpenDirectory(const fml::UniqueFD& base_directory,
45                             const char* path,
46                             bool create_if_necessary,
47                             FilePermission permission);
48 
49 fml::UniqueFD Duplicate(fml::UniqueFD::element_type descriptor);
50 
51 bool IsDirectory(const fml::UniqueFD& directory);
52 
53 // Returns whether the given path is a file.
54 bool IsFile(const std::string& path);
55 
56 bool TruncateFile(const fml::UniqueFD& file, size_t size);
57 
58 bool FileExists(const fml::UniqueFD& base_directory, const char* path);
59 
60 bool UnlinkDirectory(const char* path);
61 
62 bool UnlinkDirectory(const fml::UniqueFD& base_directory, const char* path);
63 
64 bool UnlinkFile(const char* path);
65 
66 bool UnlinkFile(const fml::UniqueFD& base_directory, const char* path);
67 
68 fml::UniqueFD CreateDirectory(const fml::UniqueFD& base_directory,
69                               const std::vector<std::string>& components,
70                               FilePermission permission);
71 
72 bool WriteAtomically(const fml::UniqueFD& base_directory,
73                      const char* file_name,
74                      const Mapping& mapping);
75 
76 class ScopedTemporaryDirectory {
77  public:
78   ScopedTemporaryDirectory();
79 
80   ~ScopedTemporaryDirectory();
81 
fd()82   const UniqueFD& fd() { return dir_fd_; }
83 
84  private:
85   std::string path_;
86   UniqueFD dir_fd_;
87 };
88 
89 }  // namespace fml
90 
91 #endif  // FLUTTER_FML_FILE_H_
92