6#if defined(DART_HOST_OS_MACOS)
30PathBuffer::~PathBuffer() {
34bool PathBuffer::AddW(
const wchar_t*
name) {
39char* PathBuffer::AsString()
const {
40 return reinterpret_cast<char*
>(data_);
43wchar_t* PathBuffer::AsStringW()
const {
48const char* PathBuffer::AsScopedString()
const {
49 return DartUtils::ScopedCopyCString(AsString());
52bool PathBuffer::Add(
const char*
name) {
53 char*
data = AsString();
68 AsString()[length_] =
'\0';
79ListType DirectoryListingEntry::Next(DirectoryListing* listing) {
86 lister_ =
reinterpret_cast<intptr_t
>(
87 opendir(listing->path_buffer().AsString()));
88 }
while ((lister_ == 0) && (errno == EINTR));
94 if (parent_ !=
nullptr) {
95 if (!listing->path_buffer().Add(File::PathSeparator())) {
99 path_length_ = listing->path_buffer().length();
102 listing->path_buffer().Reset(path_length_);
111 readdir_r(
reinterpret_cast<DIR*
>(lister_), &entry, &
result));
112 if ((status == 0) && (
result !=
nullptr)) {
113 if (!listing->path_buffer().Add(entry.d_name)) {
117 switch (entry.d_type) {
119 if ((strcmp(entry.d_name,
".") == 0) ||
120 (strcmp(entry.d_name,
"..") == 0)) {
121 return Next(listing);
131 if (!listing->follow_links()) {
141 struct stat entry_info;
144 lstat(listing->path_buffer().AsString(), &entry_info));
145 if (stat_success == -1) {
148 if (listing->follow_links() && S_ISLNK(entry_info.st_mode)) {
150 LinkList current_link = {entry_info.st_dev, entry_info.st_ino, link_};
151 LinkList* previous = link_;
152 while (previous !=
nullptr) {
153 if ((previous->dev == current_link.dev) &&
154 (previous->ino == current_link.ino)) {
158 previous = previous->next;
161 stat(listing->path_buffer().AsString(), &entry_info));
162 if (stat_success == -1 || (S_IFMT & entry_info.st_mode) == 0) {
170 if (S_ISDIR(entry_info.st_mode)) {
173 link_ =
new LinkList(current_link);
174 if ((strcmp(entry.d_name,
".") == 0) ||
175 (strcmp(entry.d_name,
"..") == 0)) {
176 return Next(listing);
181 if (S_ISDIR(entry_info.st_mode)) {
182 if ((strcmp(entry.d_name,
".") == 0) ||
183 (strcmp(entry.d_name,
"..") == 0)) {
184 return Next(listing);
187 }
else if (S_ISLNK(entry_info.st_mode)) {
198 FATAL(
"Unexpected d_type: %d\n", entry.d_type);
212DirectoryListingEntry::~DirectoryListingEntry() {
215 closedir(
reinterpret_cast<DIR*
>(lister_));
219void DirectoryListingEntry::ResetLink() {
220 if ((link_ !=
nullptr) &&
221 ((parent_ ==
nullptr) || (parent_->link_ != link_))) {
225 if (parent_ !=
nullptr) {
226 link_ = parent_->link_;
230static bool DeleteRecursively(PathBuffer*
path);
233 return path->Add(file_name) && (unlink(
path->AsString()) == 0);
236static bool DeleteDir(
char* dir_name, PathBuffer*
path) {
237 if ((strcmp(dir_name,
".") == 0) || (strcmp(dir_name,
"..") == 0)) {
240 return path->Add(dir_name) && DeleteRecursively(
path);
243static bool DeleteRecursively(PathBuffer*
path) {
249 }
else if (!S_ISDIR(st.st_mode)) {
250 return (unlink(
path->AsString()) == 0);
253 if (!
path->Add(File::PathSeparator())) {
261 dir_pointer = opendir(
path->AsString());
262 }
while ((dir_pointer ==
nullptr) && (errno == EINTR));
263 if (dir_pointer ==
nullptr) {
268 int path_length =
path->length();
278 switch (entry.d_type) {
280 ok = DeleteDir(entry.d_name,
path);
294 if (!
path->Add(entry.d_name)) {
300 struct stat entry_info;
304 path->Reset(path_length);
305 if (S_ISDIR(entry_info.st_mode)) {
306 ok = DeleteDir(entry.d_name,
path);
317 FATAL(
"Unexpected d_type: %d\n", entry.d_type);
323 path->Reset(path_length);
333Directory::ExistsResult Directory::Exists(Namespace* namespc,
334 const char* dir_name) {
335 struct stat entry_info;
338 if (S_ISDIR(entry_info.st_mode)) {
344 return DOES_NOT_EXIST;
347 if ((errno == EACCES) || (errno == EBADF) || (errno == EFAULT) ||
348 (errno == ENOMEM) || (errno == EOVERFLOW)) {
354 ASSERT((errno == ELOOP) || (errno == ENAMETOOLONG) || (errno == ENOENT) ||
356 return DOES_NOT_EXIST;
360char* Directory::CurrentNoScope() {
361 return getcwd(
nullptr, 0);
369 if ((
result == -1) && (errno == EEXIST)) {
370 return (Exists(namespc, dir_name) == EXISTS);
375const char* Directory::SystemTemp(Namespace* namespc) {
377 const char* temp_dir =
getenv(
"TMPDIR");
378 if (temp_dir ==
nullptr) {
381 if (temp_dir ==
nullptr) {
384 if (!
path.Add(temp_dir)) {
393 return path.AsScopedString();
396const char* Directory::CreateTemp(Namespace* namespc,
const char*
prefix) {
405 if (!
path.Add(
"XXXXXX")) {
412 }
while ((
result ==
nullptr) && (errno == EINTR));
416 return path.AsScopedString();
419bool Directory::Delete(Namespace* namespc,
420 const char* dir_name,
423 if ((
File::GetType(namespc, dir_name,
false) == File::kIsLink) &&
424 (
File::GetType(namespc, dir_name,
true) == File::kIsDirectory)) {
430 if (!
path.Add(dir_name)) {
433 return DeleteRecursively(&
path);
437bool Directory::Rename(Namespace* namespc,
439 const char* new_path) {
440 ExistsResult exists = Exists(namespc,
path);
441 if (exists != EXISTS) {
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)
std::shared_ptr< const fml::Mapping > data