6#if defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_ANDROID)
34PathBuffer::~PathBuffer() {
38bool PathBuffer::AddW(
const wchar_t*
name) {
43char* PathBuffer::AsString()
const {
44 return reinterpret_cast<char*
>(data_);
47wchar_t* PathBuffer::AsStringW()
const {
52const char* PathBuffer::AsScopedString()
const {
53 return DartUtils::ScopedCopyCString(AsString());
56bool PathBuffer::Add(
const char*
name) {
57 char*
data = AsString();
72 AsString()[length_] =
'\0';
78 decltype(stat64::st_dev) dev;
83ListType DirectoryListingEntry::Next(DirectoryListing* listing) {
90 NamespaceScope ns(listing->namespc(), listing->path_buffer().AsString());
102 lister_ =
reinterpret_cast<intptr_t
>(fdopendir(fd_));
103 }
while ((lister_ == 0) && (errno == EINTR));
108 if (parent_ !=
nullptr) {
109 if (!listing->path_buffer().Add(File::PathSeparator())) {
113 path_length_ = listing->path_buffer().length();
116 listing->path_buffer().Reset(path_length_);
122 dirent* entry = readdir(
reinterpret_cast<DIR*
>(lister_));
123 if (entry !=
nullptr) {
124 if (!listing->path_buffer().Add(entry->d_name)) {
128 switch (entry->d_type) {
130 if ((strcmp(entry->d_name,
".") == 0) ||
131 (strcmp(entry->d_name,
"..") == 0)) {
132 return Next(listing);
142 if (!listing->follow_links()) {
152 NamespaceScope ns(listing->namespc(),
153 listing->path_buffer().AsString());
154 struct stat64 entry_info;
157 fstatat64(ns.fd(), ns.path(), &entry_info, AT_SYMLINK_NOFOLLOW));
158 if (stat_success == -1) {
161 if (listing->follow_links() && S_ISLNK(entry_info.st_mode)) {
163 LinkList current_link = {entry_info.st_dev, entry_info.st_ino, link_};
164 LinkList* previous = link_;
165 while (previous !=
nullptr) {
166 if ((previous->dev == current_link.dev) &&
167 (previous->ino == current_link.ino)) {
171 previous = previous->next;
175 if (stat_success == -1 || (S_IFMT & entry_info.st_mode) == 0) {
183 if (S_ISDIR(entry_info.st_mode)) {
186 link_ =
new LinkList(current_link);
187 if ((strcmp(entry->d_name,
".") == 0) ||
188 (strcmp(entry->d_name,
"..") == 0)) {
189 return Next(listing);
194 if (S_ISDIR(entry_info.st_mode)) {
195 if ((strcmp(entry->d_name,
".") == 0) ||
196 (strcmp(entry->d_name,
"..") == 0)) {
197 return Next(listing);
200 }
else if (S_ISLNK(entry_info.st_mode)) {
211 FATAL(
"Unexpected d_type: %d\n", entry->d_type);
224DirectoryListingEntry::~DirectoryListingEntry() {
232void DirectoryListingEntry::ResetLink() {
233 if ((link_ !=
nullptr) &&
234 ((parent_ ==
nullptr) || (parent_->link_ != link_))) {
238 if (parent_ !=
nullptr) {
239 link_ = parent_->link_;
243static bool DeleteRecursively(
int dirfd, PathBuffer*
path);
245static bool DeleteFile(
int dirfd,
char* file_name, PathBuffer*
path) {
246 return path->Add(file_name) &&
250static bool DeleteDir(
int dirfd,
char* dir_name, PathBuffer*
path) {
251 if ((strcmp(dir_name,
".") == 0) || (strcmp(dir_name,
"..") == 0)) {
254 return path->Add(dir_name) && DeleteRecursively(dirfd,
path);
257static bool DeleteRecursively(
int dirfd, PathBuffer*
path) {
262 fstatat64(dirfd,
path->AsString(), &st, AT_SYMLINK_NOFOLLOW)) == -1) {
264 }
else if (!S_ISDIR(st.st_mode)) {
268 if (!
path->Add(File::PathSeparator())) {
281 dir_pointer = fdopendir(fd);
282 }
while ((dir_pointer ==
nullptr) && (errno == EINTR));
283 if (dir_pointer ==
nullptr) {
284 FDUtils::SaveErrorAndClose(fd);
289 int path_length =
path->length();
299 dirent* entry = readdir(dir_pointer);
300 if (entry ==
nullptr) {
315 switch (entry->d_type) {
317 ok = DeleteDir(dirfd, entry->d_name,
path);
331 if (!
path->Add(entry->d_name)) {
337 struct stat64 entry_info;
339 AT_SYMLINK_NOFOLLOW)) == -1) {
342 path->Reset(path_length);
343 if (S_ISDIR(entry_info.st_mode)) {
344 ok = DeleteDir(dirfd, entry->d_name,
path);
355 FATAL(
"Unexpected d_type: %d\n", entry->d_type);
361 path->Reset(path_length);
371Directory::ExistsResult Directory::Exists(Namespace* namespc,
372 const char* dir_name) {
373 NamespaceScope ns(namespc, dir_name);
374 struct stat64 entry_info;
378 if (S_ISDIR(entry_info.st_mode)) {
384 return DOES_NOT_EXIST;
387 if ((errno == EACCES) || (errno == EBADF) || (errno == EFAULT) ||
388 (errno == ENOMEM) || (errno == EOVERFLOW)) {
394 ASSERT((errno == ELOOP) || (errno == ENAMETOOLONG) || (errno == ENOENT) ||
396 return DOES_NOT_EXIST;
400char* Directory::CurrentNoScope() {
401 return getcwd(
nullptr, 0);
405 NamespaceScope ns(namespc, dir_name);
410 if ((
result == -1) && (errno == EEXIST)) {
411 return (Exists(namespc, dir_name) == EXISTS);
416const char* Directory::SystemTemp(Namespace* namespc) {
417 if (Directory::system_temp_path_override_ !=
nullptr) {
418 return DartUtils::ScopedCopyCString(Directory::system_temp_path_override_);
422 const char* temp_dir =
getenv(
"TMPDIR");
423 if (temp_dir ==
nullptr) {
426 if (temp_dir ==
nullptr) {
427#if defined(DART_HOST_OS_ANDROID)
428 temp_dir =
"/data/local/tmp";
433 NamespaceScope ns(namespc, temp_dir);
434 if (!
path.Add(ns.path())) {
444 return path.AsScopedString();
451const char* Directory::CreateTemp(Namespace* namespc,
const char*
prefix) {
453 const int firstchar =
'A';
454 const int numchars =
'Z' -
'A' + 1;
455 uint8_t random_bytes[7];
461 intptr_t prefix_length =
path.length();
463 Crypto::GetRandomBytes(6, random_bytes);
464 for (intptr_t
i = 0;
i < 6;
i++) {
465 random_bytes[
i] = (random_bytes[
i] % numchars) + firstchar;
467 random_bytes[6] =
'\0';
468 if (!
path.Add(
reinterpret_cast<char*
>(random_bytes))) {
471 NamespaceScope ns(namespc,
path.AsString());
474 return path.AsScopedString();
475 }
else if (errno == EEXIST) {
476 path.Reset(prefix_length);
483bool Directory::Delete(Namespace* namespc,
484 const char* dir_name,
486 NamespaceScope ns(namespc, dir_name);
488 if ((
File::GetType(namespc, dir_name,
false) == File::kIsLink) &&
489 (
File::GetType(namespc, dir_name,
true) == File::kIsDirectory)) {
495 if (!
path.Add(ns.path())) {
498 return DeleteRecursively(ns.fd(), &
path);
502bool Directory::Rename(Namespace* namespc,
503 const char* old_path,
504 const char* new_path) {
505 ExistsResult exists = Exists(namespc, old_path);
506 if (exists != EXISTS) {
509 NamespaceScope oldns(namespc, old_path);
510 NamespaceScope newns(namespc, new_path);
512 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