forked from flutter/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
file.h
91 lines (62 loc) · 2.36 KB
/
file.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef FLUTTER_FML_FILE_H_
#define FLUTTER_FML_FILE_H_
#include <initializer_list>
#include <string>
#include <vector>
#include "flutter/fml/macros.h"
#include "flutter/fml/unique_fd.h"
#ifdef ERROR
#undef ERROR
#endif
namespace fml {
class Mapping;
enum class FilePermission {
kRead,
kWrite,
kReadWrite,
};
std::string CreateTemporaryDirectory();
fml::UniqueFD OpenFile(const char* path,
bool create_if_necessary,
FilePermission permission);
fml::UniqueFD OpenFile(const fml::UniqueFD& base_directory,
const char* path,
bool create_if_necessary,
FilePermission permission);
fml::UniqueFD OpenDirectory(const char* path,
bool create_if_necessary,
FilePermission permission);
fml::UniqueFD OpenDirectory(const fml::UniqueFD& base_directory,
const char* path,
bool create_if_necessary,
FilePermission permission);
fml::UniqueFD Duplicate(fml::UniqueFD::element_type descriptor);
bool IsDirectory(const fml::UniqueFD& directory);
// Returns whether the given path is a file.
bool IsFile(const std::string& path);
bool TruncateFile(const fml::UniqueFD& file, size_t size);
bool FileExists(const fml::UniqueFD& base_directory, const char* path);
bool UnlinkDirectory(const char* path);
bool UnlinkDirectory(const fml::UniqueFD& base_directory, const char* path);
bool UnlinkFile(const char* path);
bool UnlinkFile(const fml::UniqueFD& base_directory, const char* path);
fml::UniqueFD CreateDirectory(const fml::UniqueFD& base_directory,
const std::vector<std::string>& components,
FilePermission permission);
bool WriteAtomically(const fml::UniqueFD& base_directory,
const char* file_name,
const Mapping& mapping);
class ScopedTemporaryDirectory {
public:
ScopedTemporaryDirectory();
~ScopedTemporaryDirectory();
const UniqueFD& fd() { return dir_fd_; }
private:
std::string path_;
UniqueFD dir_fd_;
};
} // namespace fml
#endif // FLUTTER_FML_FILE_H_