6#if defined(DART_HOST_OS_FUCHSIA)
13#include <lib/fdio/namespace.h>
35PathBuffer::~PathBuffer() {
39bool PathBuffer::AddW(
const wchar_t*
name) {
44char* PathBuffer::AsString()
const {
45 return reinterpret_cast<char*
>(data_);
48wchar_t* PathBuffer::AsStringW()
const {
53const char* PathBuffer::AsScopedString()
const {
54 return DartUtils::ScopedCopyCString(AsString());
57bool PathBuffer::Add(
const char*
name) {
58 const intptr_t name_length = strnlen(
name,
PATH_MAX + 1);
59 if (name_length == 0) {
63 char*
data = AsString();
78 AsString()[length_] =
'\0';
89ListType DirectoryListingEntry::Next(DirectoryListing* listing) {
96 NamespaceScope ns(listing->namespc(), listing->path_buffer().AsString());
108 lister_ =
reinterpret_cast<intptr_t
>(fdopendir(fd_));
109 }
while ((lister_ == 0) && (errno == EINTR));
114 if (parent_ !=
nullptr) {
115 if (!listing->path_buffer().Add(File::PathSeparator())) {
119 path_length_ = listing->path_buffer().length();
122 listing->path_buffer().Reset(path_length_);
128 dirent* entry = readdir(
reinterpret_cast<DIR*
>(lister_));
129 if (entry !=
nullptr) {
130 if (!listing->path_buffer().Add(entry->d_name)) {
134 switch (entry->d_type) {
136 if ((strcmp(entry->d_name,
".") == 0) ||
137 (strcmp(entry->d_name,
"..") == 0)) {
138 return Next(listing);
148 if (!listing->follow_links()) {
158 NamespaceScope ns(listing->namespc(),
159 listing->path_buffer().AsString());
160 struct stat entry_info;
163 fstatat(ns.fd(), ns.path(), &entry_info, AT_SYMLINK_NOFOLLOW));
164 if (stat_success == -1) {
167 if (listing->follow_links() && S_ISLNK(entry_info.st_mode)) {
169 LinkList current_link = {entry_info.st_dev, entry_info.st_ino, link_};
170 LinkList* previous = link_;
171 while (previous !=
nullptr) {
172 if ((previous->dev == current_link.dev) &&
173 (previous->ino == current_link.ino)) {
177 previous = previous->next;
181 if (stat_success == -1 || (S_IFMT & entry_info.st_mode) == 0) {
189 if (S_ISDIR(entry_info.st_mode)) {
192 link_ =
new LinkList(current_link);
193 if ((strcmp(entry->d_name,
".") == 0) ||
194 (strcmp(entry->d_name,
"..") == 0)) {
195 return Next(listing);
200 if (S_ISDIR(entry_info.st_mode)) {
201 if ((strcmp(entry->d_name,
".") == 0) ||
202 (strcmp(entry->d_name,
"..") == 0)) {
203 return Next(listing);
206 }
else if (S_ISLNK(entry_info.st_mode)) {
217 FATAL(
"Unexpected d_type: %d\n", entry->d_type);
230DirectoryListingEntry::~DirectoryListingEntry() {
238void DirectoryListingEntry::ResetLink() {
239 if ((link_ !=
nullptr) &&
240 ((parent_ ==
nullptr) || (parent_->link_ != link_))) {
244 if (parent_ !=
nullptr) {
245 link_ = parent_->link_;
249Directory::ExistsResult Directory::Exists(Namespace* namespc,
250 const char* dir_name) {
251 NamespaceScope ns(namespc, dir_name);
252 struct stat entry_info;
256 if (S_ISDIR(entry_info.st_mode)) {
262 return DOES_NOT_EXIST;
265 if ((errno == EACCES) || (errno == EBADF) || (errno == EFAULT) ||
266 (errno == ENOMEM) || (errno == EOVERFLOW)) {
272 ASSERT((errno == ELOOP) || (errno == ENAMETOOLONG) || (errno == ENOENT) ||
274 return DOES_NOT_EXIST;
278char* Directory::CurrentNoScope() {
279 return getcwd(
nullptr, 0);
283 NamespaceScope ns(namespc, dir_name);
288 if ((
result == -1) && (errno == EEXIST)) {
289 return (Exists(namespc, dir_name) == EXISTS);
294const char* Directory::SystemTemp(Namespace* namespc) {
296 const char* temp_dir =
getenv(
"TMPDIR");
297 if (temp_dir ==
nullptr) {
300 if (temp_dir ==
nullptr) {
303 NamespaceScope ns(namespc, temp_dir);
304 if (!
path.Add(ns.path())) {
314 return path.AsScopedString();
321const char* Directory::CreateTemp(Namespace* namespc,
const char*
prefix) {
323 const int firstchar =
'A';
324 const int numchars =
'Z' -
'A' + 1;
325 uint8_t random_bytes[7];
331 intptr_t prefix_length =
path.length();
333 Crypto::GetRandomBytes(6, random_bytes);
334 for (intptr_t
i = 0;
i < 6;
i++) {
335 random_bytes[
i] = (random_bytes[
i] % numchars) + firstchar;
337 random_bytes[6] =
'\0';
338 if (!
path.Add(
reinterpret_cast<char*
>(random_bytes))) {
341 NamespaceScope ns(namespc,
path.AsString());
344 return path.AsScopedString();
345 }
else if (errno == EEXIST) {
346 path.Reset(prefix_length);
353static bool DeleteRecursively(
int dirfd, PathBuffer*
path);
355static bool DeleteFile(
int dirfd,
char* file_name, PathBuffer*
path) {
356 return path->Add(file_name) &&
360static bool DeleteDir(
int dirfd,
char* dir_name, PathBuffer*
path) {
361 if ((strcmp(dir_name,
".") == 0) || (strcmp(dir_name,
"..") == 0)) {
364 return path->Add(dir_name) && DeleteRecursively(dirfd,
path);
367static bool DeleteRecursively(
int dirfd, PathBuffer*
path) {
372 fstatat(dirfd,
path->AsString(), &st, AT_SYMLINK_NOFOLLOW)) == -1) {
374 }
else if (!S_ISDIR(st.st_mode)) {
378 if (!
path->Add(File::PathSeparator())) {
391 dir_pointer = fdopendir(fd);
392 }
while ((dir_pointer ==
nullptr) && (errno == EINTR));
393 if (dir_pointer ==
nullptr) {
394 FDUtils::SaveErrorAndClose(fd);
399 int path_length =
path->length();
409 dirent* entry = readdir(dir_pointer);
410 if (entry ==
nullptr) {
425 switch (entry->d_type) {
427 ok = DeleteDir(dirfd, entry->d_name,
path);
441 if (!
path->Add(entry->d_name)) {
447 struct stat entry_info;
449 AT_SYMLINK_NOFOLLOW)) == -1) {
452 path->Reset(path_length);
453 if (S_ISDIR(entry_info.st_mode)) {
454 ok = DeleteDir(dirfd, entry->d_name,
path);
465 FATAL(
"Unexpected d_type: %d\n", entry->d_type);
471 path->Reset(path_length);
481bool Directory::Delete(Namespace* namespc,
482 const char* dir_name,
484 NamespaceScope ns(namespc, dir_name);
486 if ((
File::GetType(namespc, dir_name,
false) == File::kIsLink) &&
487 (
File::GetType(namespc, dir_name,
true) == File::kIsDirectory)) {
493 if (!
path.Add(ns.path())) {
496 return DeleteRecursively(ns.fd(), &
path);
500bool Directory::Rename(Namespace* namespc,
501 const char* old_path,
502 const char* new_path) {
503 ExistsResult exists = Exists(namespc, old_path);
504 if (exists != EXISTS) {
507 NamespaceScope oldns(namespc, old_path);
508 NamespaceScope newns(namespc, new_path);
510 newns.path())) == 0);
static float next(float f)
static sk_sp< Effect > Create()
static bool ok(int result)
void * calloc(size_t n, size_t size)
static Dart_TypedData_Type GetType(intptr_t class_id)
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
DEF_SWITCHES_START aot vmservice shared library name
#define NO_RETRY_EXPECTED(expression)
#define VOID_NO_RETRY_EXPECTED(expression)
#define TEMP_FAILURE_RETRY(expression)
std::shared_ptr< const fml::Mapping > data