5 #include "flutter/fml/file.h" 16 #include "flutter/fml/eintr_wrapper.h" 17 #include "flutter/fml/logging.h" 18 #include "flutter/fml/mapping.h" 19 #include "flutter/fml/trace_event.h" 20 #include "flutter/fml/unique_fd.h" 25 char directory_name[] =
"/tmp/flutter_XXXXXXXX";
26 auto*
result = ::mkdtemp(directory_name);
59 mode |= S_IRUSR | S_IWUSR;
66 bool create_if_necessary,
74 bool create_if_necessary,
77 if (path ==
nullptr) {
84 if (create_if_necessary && !
FileExists(base_directory, path)) {
97 bool create_if_necessary,
105 bool create_if_necessary,
107 if (path ==
nullptr) {
111 if (create_if_necessary && !
FileExists(base_directory, path)) {
112 if (::mkdirat(base_directory.
get(),
path,
119 ::openat(base_directory.
get(),
path, O_RDONLY | O_DIRECTORY))};
131 struct stat stat_result = {};
133 if (::fstat(directory.
get(), &stat_result) != 0) {
137 return S_ISDIR(stat_result.st_mode);
147 if (stat(path.c_str(), &buf) != 0) {
151 return S_ISREG(buf.st_mode);
159 return ::ftruncate(file.
get(),
size) == 0;
167 return ::unlinkat(base_directory.
get(),
path, AT_REMOVEDIR) == 0;
175 int code = ::unlinkat(base_directory.
get(),
path, 0);
187 return ::faccessat(base_directory.
get(),
path, F_OK, 0) == 0;
191 const char* file_name,
193 if (file_name ==
nullptr || data.
GetMapping() ==
nullptr) {
197 std::stringstream stream;
198 stream << file_name <<
".temp";
199 const auto temp_file_name = stream.str();
201 auto temp_file =
OpenFile(base_directory, temp_file_name.c_str(),
true,
203 if (!temp_file.is_valid()) {
211 ssize_t remaining = data.
GetSize();
215 while (remaining > 0) {
217 ::write(temp_file.get(), data.
GetMapping() + offset, remaining));
223 remaining -= written;
227 if (::fsync(temp_file.get()) != 0) {
231 return ::renameat(base_directory.
get(), temp_file_name.c_str(),
232 base_directory.
get(), file_name) == 0;
238 FML_DLOG(ERROR) <<
"Can't dup the directory fd. Error: " << strerror(errno);
244 FML_DLOG(ERROR) <<
"Can't open the directory. Error: " << strerror(errno);
254 rewinddir(dir.
get());
255 while (dirent* ent = readdir(dir.
get())) {
256 std::string filename = ent->d_name;
257 if (filename !=
"." && filename !=
"..") {
258 if (!visitor(directory, filename)) {
static int ToPosixCreateModeFlags(FilePermission permission)
#define TRACE_EVENT0(category_group, name)
std::string CreateTemporaryDirectory()
virtual size_t GetSize() const =0
std::function< bool(const fml::UniqueFD &directory, const std::string &filename)> FileVisitor
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data observatory The hostname IP address on which the Dart Observatory should be served If not defaults to or::depending on whether ipv6 is specified disable Disable the Dart Observatory The observatory is never available in release mode Bind to the IPv6 localhost address for the Dart Observatory Ignored if observatory host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets dir
virtual const uint8_t * GetMapping() const =0
constexpr std::size_t size(T(&array)[N])
fml::UniqueFD Duplicate(fml::UniqueFD::element_type descriptor)
FlutterSemanticsFlag flags
fml::UniqueFD OpenDirectory(const char *path, bool create_if_necessary, FilePermission permission)
bool VisitFiles(const fml::UniqueFD &directory, const FileVisitor &visitor)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
#define FML_HANDLE_EINTR(x)
bool IsDirectory(const fml::UniqueFD &directory)
bool FileExists(const fml::UniqueFD &base_directory, const char *path)
bool UnlinkFile(const char *path)
bool IsFile(const std::string &path)
static int ToPosixAccessFlags(FilePermission permission)
fml::UniqueFD OpenFile(const char *path, bool create_if_necessary, FilePermission permission)
This can open a directory on POSIX, but not on Windows.
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
#define FML_DLOG(severity)
bool TruncateFile(const fml::UniqueFD &file, size_t size)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data observatory The hostname IP address on which the Dart Observatory should be served If not defaults to or::depending on whether ipv6 is specified disable Disable the Dart Observatory The observatory is never available in release mode Bind to the IPv6 localhost address for the Dart Observatory Ignored if observatory host is set endless trace Enable an endless trace buffer The default is a ring buffer This is useful when very old events need to viewed For during application launch Memory usage will continue to grow indefinitely however Start app with an specific route defined on the framework flutter assets Path to the Flutter assets directory enable service port Allow the VM service to fallback to automatic port selection if binding to a specified port fails trace Trace early application lifecycle Automatically switches to an endless trace buffer trace skia Filters out all Skia trace event categories except those that are specified in this comma separated list dump skp on shader Automatically dump the skp that triggers new shader compilations This is useful for writing custom ShaderWarmUp to reduce jank By this is not enabled to reduce the overhead purge persistent Remove all existing persistent cache This is mainly for debugging purposes such as reproducing the shader compilation jank use test Running tests that layout and measure text will not yield consistent results across various platforms Enabling this option will make font resolution default to the Ahem test font on all disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
bool WriteAtomically(const fml::UniqueFD &base_directory, const char *file_name, const Mapping &mapping)
bool UnlinkDirectory(const char *path)
fml::UniqueFD OpenFileReadOnly(const fml::UniqueFD &base_directory, const char *path)