-
Notifications
You must be signed in to change notification settings - Fork 6k
SkSL precompile #12412
SkSL precompile #12412
Changes from all commits
6d2e85e
d7fd345
5ac4685
940e80f
2c41d1d
5bf0c7b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
|
||
#include "flutter/fml/file.h" | ||
|
||
#include <dirent.h> | ||
#include <fcntl.h> | ||
#include <sys/mman.h> | ||
#include <sys/stat.h> | ||
|
@@ -13,7 +14,9 @@ | |
#include <sstream> | ||
|
||
#include "flutter/fml/eintr_wrapper.h" | ||
#include "flutter/fml/logging.h" | ||
#include "flutter/fml/mapping.h" | ||
#include "flutter/fml/unique_fd.h" | ||
|
||
namespace fml { | ||
|
||
|
@@ -132,6 +135,11 @@ bool IsDirectory(const fml::UniqueFD& directory) { | |
return S_ISDIR(stat_result.st_mode); | ||
} | ||
|
||
bool IsDirectory(const fml::UniqueFD& base_directory, const char* path) { | ||
UniqueFD file = OpenFileReadOnly(base_directory, path); | ||
return (file.is_valid() && IsDirectory(file)); | ||
} | ||
|
||
bool IsFile(const std::string& path) { | ||
struct stat buf; | ||
if (stat(path.c_str(), &buf) != 0) { | ||
|
@@ -162,7 +170,11 @@ bool UnlinkFile(const char* path) { | |
} | ||
|
||
bool UnlinkFile(const fml::UniqueFD& base_directory, const char* path) { | ||
return ::unlinkat(base_directory.get(), path, 0) == 0; | ||
int code = ::unlinkat(base_directory.get(), path, 0); | ||
if (code != 0) { | ||
FML_DLOG(ERROR) << strerror(errno); | ||
} | ||
return code == 0; | ||
} | ||
|
||
bool FileExists(const fml::UniqueFD& base_directory, const char* path) { | ||
|
@@ -210,4 +222,29 @@ bool WriteAtomically(const fml::UniqueFD& base_directory, | |
base_directory.get(), file_name) == 0; | ||
} | ||
|
||
bool VisitFiles(const fml::UniqueFD& directory, FileVisitor visitor) { | ||
// We cannot call closedir(dir) because it will also close the corresponding | ||
// UniqueFD, and later reference to that UniqueFD will fail. Also, we don't | ||
// have to call closedir because UniqueFD will call close on its destructor. | ||
DIR* dir = ::fdopendir(directory.get()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is being leaked without a balancing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We cannot call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #12412 (comment) |
||
if (dir == nullptr) { | ||
FML_DLOG(ERROR) << "Can't open the directory. Error: " << strerror(errno); | ||
return true; // continue to visit other files | ||
} | ||
|
||
// Without `rewinddir`, `readir` will directly return NULL (end of dir is | ||
// reached) after a previuos `VisitFiles` call for the same `const | ||
// fml::UniqueFd& directory`. | ||
rewinddir(dir); | ||
while (dirent* ent = readdir(dir)) { | ||
std::string filename = ent->d_name; | ||
if (filename != "." && filename != "..") { | ||
if (!visitor(directory, filename)) { | ||
return false; | ||
} | ||
} | ||
} | ||
return true; | ||
} | ||
|
||
} // namespace fml |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: you could use nftw https://linux.die.net/man/3/nftw to simplify this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah,
nftw
looks useful. Do you also happen to know the corresponding API for Windows? I wonder if I shall adjust our API to be more close tontfw
(e.g., providenopenfd
argument)