| Index: runtime/bin/directory_fuchsia.cc
|
| diff --git a/runtime/bin/directory_fuchsia.cc b/runtime/bin/directory_fuchsia.cc
|
| index 1e374d1617e5189f5bf0377d9dd3013bfd61bcd2..1593ff717244ac0ee173a7ae5cd3a89cbced5ca1 100644
|
| --- a/runtime/bin/directory_fuchsia.cc
|
| +++ b/runtime/bin/directory_fuchsia.cc
|
| @@ -143,38 +143,89 @@ const char* Directory::Current() {
|
|
|
|
|
| bool Directory::SetCurrent(const char* path) {
|
| - UNIMPLEMENTED();
|
| - return false;
|
| + return (NO_RETRY_EXPECTED(chdir(path)) == 0);
|
| }
|
|
|
|
|
| bool Directory::Create(const char* dir_name) {
|
| - UNIMPLEMENTED();
|
| - return false;
|
| + // Create the directory with the permissions specified by the
|
| + // process umask.
|
| + int result = NO_RETRY_EXPECTED(mkdir(dir_name, 0777));
|
| + // If the directory already exists, treat it as a success.
|
| + if ((result == -1) && (errno == EEXIST)) {
|
| + return (Exists(dir_name) == EXISTS);
|
| + }
|
| + return (result == 0);
|
| }
|
|
|
|
|
| const char* Directory::SystemTemp() {
|
| - UNIMPLEMENTED();
|
| - return NULL;
|
| + PathBuffer path;
|
| + const char* temp_dir = getenv("TMPDIR");
|
| + if (temp_dir == NULL) {
|
| + temp_dir = getenv("TMP");
|
| + }
|
| + if (temp_dir == NULL) {
|
| + temp_dir = "/tmp";
|
| + }
|
| + if (!path.Add(temp_dir)) {
|
| + return NULL;
|
| + }
|
| +
|
| + // Remove any trailing slash.
|
| + char* result = path.AsString();
|
| + int length = strlen(result);
|
| + if ((length > 1) && (result[length - 1] == '/')) {
|
| + result[length - 1] = '\0';
|
| + }
|
| + return path.AsScopedString();
|
| }
|
|
|
|
|
| const char* Directory::CreateTemp(const char* prefix) {
|
| - UNIMPLEMENTED();
|
| - return NULL;
|
| + // Returns a new, unused directory name, adding characters to the end
|
| + // of prefix. Creates the directory with the permissions specified
|
| + // by the process umask.
|
| + // The return value is Dart_ScopeAllocated.
|
| + PathBuffer path;
|
| + if (!path.Add(prefix)) {
|
| + return NULL;
|
| + }
|
| + if (!path.Add("XXXXXX")) {
|
| + // Pattern has overflowed.
|
| + return NULL;
|
| + }
|
| + char* result;
|
| + do {
|
| + result = mkdtemp(path.AsString());
|
| + } while ((result == NULL) && (errno == EINTR));
|
| + if (result == NULL) {
|
| + return NULL;
|
| + }
|
| + return path.AsScopedString();
|
| }
|
|
|
|
|
| bool Directory::Delete(const char* dir_name, bool recursive) {
|
| - UNIMPLEMENTED();
|
| - return false;
|
| + if (!recursive) {
|
| + if ((File::GetType(dir_name, false) == File::kIsLink) &&
|
| + (File::GetType(dir_name, true) == File::kIsDirectory)) {
|
| + return NO_RETRY_EXPECTED(unlink(dir_name)) == 0;
|
| + }
|
| + return NO_RETRY_EXPECTED(rmdir(dir_name)) == 0;
|
| + } else {
|
| + UNIMPLEMENTED();
|
| + return false;
|
| + }
|
| }
|
|
|
|
|
| bool Directory::Rename(const char* path, const char* new_path) {
|
| - UNIMPLEMENTED();
|
| - return false;
|
| + ExistsResult exists = Exists(path);
|
| + if (exists != EXISTS) {
|
| + return false;
|
| + }
|
| + return (NO_RETRY_EXPECTED(rename(path, new_path)) == 0);
|
| }
|
|
|
| } // namespace bin
|
|
|