| OLD | NEW |
| 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "platform/globals.h" | 5 #include "platform/globals.h" |
| 6 #if defined(TARGET_OS_FUCHSIA) | 6 #if defined(TARGET_OS_FUCHSIA) |
| 7 | 7 |
| 8 #include "bin/directory.h" | 8 #include "bin/directory.h" |
| 9 | 9 |
| 10 #include <errno.h> // NOLINT | 10 #include <errno.h> // NOLINT |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 const char* Directory::Current() { | 136 const char* Directory::Current() { |
| 137 char buffer[PATH_MAX]; | 137 char buffer[PATH_MAX]; |
| 138 if (getcwd(buffer, PATH_MAX) == NULL) { | 138 if (getcwd(buffer, PATH_MAX) == NULL) { |
| 139 return NULL; | 139 return NULL; |
| 140 } | 140 } |
| 141 return DartUtils::ScopedCopyCString(buffer); | 141 return DartUtils::ScopedCopyCString(buffer); |
| 142 } | 142 } |
| 143 | 143 |
| 144 | 144 |
| 145 bool Directory::SetCurrent(const char* path) { | 145 bool Directory::SetCurrent(const char* path) { |
| 146 UNIMPLEMENTED(); | 146 return (NO_RETRY_EXPECTED(chdir(path)) == 0); |
| 147 return false; | |
| 148 } | 147 } |
| 149 | 148 |
| 150 | 149 |
| 151 bool Directory::Create(const char* dir_name) { | 150 bool Directory::Create(const char* dir_name) { |
| 152 UNIMPLEMENTED(); | 151 // Create the directory with the permissions specified by the |
| 153 return false; | 152 // process umask. |
| 153 int result = NO_RETRY_EXPECTED(mkdir(dir_name, 0777)); |
| 154 // If the directory already exists, treat it as a success. |
| 155 if ((result == -1) && (errno == EEXIST)) { |
| 156 return (Exists(dir_name) == EXISTS); |
| 157 } |
| 158 return (result == 0); |
| 154 } | 159 } |
| 155 | 160 |
| 156 | 161 |
| 157 const char* Directory::SystemTemp() { | 162 const char* Directory::SystemTemp() { |
| 158 UNIMPLEMENTED(); | 163 PathBuffer path; |
| 159 return NULL; | 164 const char* temp_dir = getenv("TMPDIR"); |
| 165 if (temp_dir == NULL) { |
| 166 temp_dir = getenv("TMP"); |
| 167 } |
| 168 if (temp_dir == NULL) { |
| 169 temp_dir = "/tmp"; |
| 170 } |
| 171 if (!path.Add(temp_dir)) { |
| 172 return NULL; |
| 173 } |
| 174 |
| 175 // Remove any trailing slash. |
| 176 char* result = path.AsString(); |
| 177 int length = strlen(result); |
| 178 if ((length > 1) && (result[length - 1] == '/')) { |
| 179 result[length - 1] = '\0'; |
| 180 } |
| 181 return path.AsScopedString(); |
| 160 } | 182 } |
| 161 | 183 |
| 162 | 184 |
| 163 const char* Directory::CreateTemp(const char* prefix) { | 185 const char* Directory::CreateTemp(const char* prefix) { |
| 164 UNIMPLEMENTED(); | 186 // Returns a new, unused directory name, adding characters to the end |
| 165 return NULL; | 187 // of prefix. Creates the directory with the permissions specified |
| 188 // by the process umask. |
| 189 // The return value is Dart_ScopeAllocated. |
| 190 PathBuffer path; |
| 191 if (!path.Add(prefix)) { |
| 192 return NULL; |
| 193 } |
| 194 if (!path.Add("XXXXXX")) { |
| 195 // Pattern has overflowed. |
| 196 return NULL; |
| 197 } |
| 198 char* result; |
| 199 do { |
| 200 result = mkdtemp(path.AsString()); |
| 201 } while ((result == NULL) && (errno == EINTR)); |
| 202 if (result == NULL) { |
| 203 return NULL; |
| 204 } |
| 205 return path.AsScopedString(); |
| 166 } | 206 } |
| 167 | 207 |
| 168 | 208 |
| 169 bool Directory::Delete(const char* dir_name, bool recursive) { | 209 bool Directory::Delete(const char* dir_name, bool recursive) { |
| 170 UNIMPLEMENTED(); | 210 if (!recursive) { |
| 171 return false; | 211 if ((File::GetType(dir_name, false) == File::kIsLink) && |
| 212 (File::GetType(dir_name, true) == File::kIsDirectory)) { |
| 213 return NO_RETRY_EXPECTED(unlink(dir_name)) == 0; |
| 214 } |
| 215 return NO_RETRY_EXPECTED(rmdir(dir_name)) == 0; |
| 216 } else { |
| 217 UNIMPLEMENTED(); |
| 218 return false; |
| 219 } |
| 172 } | 220 } |
| 173 | 221 |
| 174 | 222 |
| 175 bool Directory::Rename(const char* path, const char* new_path) { | 223 bool Directory::Rename(const char* path, const char* new_path) { |
| 176 UNIMPLEMENTED(); | 224 ExistsResult exists = Exists(path); |
| 177 return false; | 225 if (exists != EXISTS) { |
| 226 return false; |
| 227 } |
| 228 return (NO_RETRY_EXPECTED(rename(path, new_path)) == 0); |
| 178 } | 229 } |
| 179 | 230 |
| 180 } // namespace bin | 231 } // namespace bin |
| 181 } // namespace dart | 232 } // namespace dart |
| 182 | 233 |
| 183 #endif // defined(TARGET_OS_LINUX) | 234 #endif // defined(TARGET_OS_LINUX) |
| OLD | NEW |