OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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_LINUX) | 6 #if defined(TARGET_OS_LINUX) |
7 | 7 |
8 #include "bin/directory.h" | 8 #include "bin/directory.h" |
9 | 9 |
10 #include <dirent.h> // NOLINT | 10 #include <dirent.h> // NOLINT |
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 success = false; | 214 success = false; |
215 PostError(listing, path->data); | 215 PostError(listing, path->data); |
216 } | 216 } |
217 | 217 |
218 return success; | 218 return success; |
219 } | 219 } |
220 | 220 |
221 | 221 |
222 static bool DeleteFile(char* file_name, | 222 static bool DeleteFile(char* file_name, |
223 PathBuffer* path) { | 223 PathBuffer* path) { |
224 return path->Add(file_name) && remove(path->data) == 0; | 224 return path->Add(file_name) && unlink(path->data) == 0; |
225 } | 225 } |
226 | 226 |
227 | 227 |
228 static bool DeleteDir(char* dir_name, | 228 static bool DeleteDir(char* dir_name, |
229 PathBuffer* path) { | 229 PathBuffer* path) { |
230 if (strcmp(dir_name, ".") == 0) return true; | 230 if (strcmp(dir_name, ".") == 0) return true; |
231 if (strcmp(dir_name, "..") == 0) return true; | 231 if (strcmp(dir_name, "..") == 0) return true; |
232 return path->Add(dir_name) && DeleteRecursively(path); | 232 return path->Add(dir_name) && DeleteRecursively(path); |
233 } | 233 } |
234 | 234 |
235 | 235 |
236 static bool DeleteRecursively(PathBuffer* path) { | 236 static bool DeleteRecursively(PathBuffer* path) { |
237 // Do not recurse into links for deletion. Instead delete the link. | 237 // Do not recurse into links for deletion. Instead delete the link. |
| 238 // If it's a file, delete it. |
238 struct stat st; | 239 struct stat st; |
239 if (TEMP_FAILURE_RETRY(lstat(path->data, &st)) == -1) { | 240 if (TEMP_FAILURE_RETRY(lstat(path->data, &st)) == -1) { |
240 return false; | 241 return false; |
241 } else if (S_ISLNK(st.st_mode)) { | 242 } else if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) { |
242 if (TEMP_FAILURE_RETRY(stat(path->data, &st)) == -1) { | 243 return (unlink(path->data) == 0); |
243 return false; | |
244 } else if (S_ISDIR(st.st_mode)) { | |
245 return (unlink(path->data) == 0); | |
246 } | |
247 } | 244 } |
248 | 245 |
249 if (!path->Add(File::PathSeparator())) return false; | 246 if (!path->Add(File::PathSeparator())) return false; |
250 | 247 |
251 // Not a link. Attempt to open as a directory and recurse into the | 248 // Not a link. Attempt to open as a directory and recurse into the |
252 // directory. | 249 // directory. |
253 DIR* dir_pointer; | 250 DIR* dir_pointer; |
254 do { | 251 do { |
255 dir_pointer = opendir(path->data); | 252 dir_pointer = opendir(path->data); |
256 } while (dir_pointer == NULL && errno == EINTR); | 253 } while (dir_pointer == NULL && errno == EINTR); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
428 } | 425 } |
429 | 426 |
430 | 427 |
431 bool Directory::Rename(const char* path, const char* new_path) { | 428 bool Directory::Rename(const char* path, const char* new_path) { |
432 ExistsResult exists = Exists(path); | 429 ExistsResult exists = Exists(path); |
433 if (exists != EXISTS) return false; | 430 if (exists != EXISTS) return false; |
434 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); | 431 return (TEMP_FAILURE_RETRY(rename(path, new_path)) == 0); |
435 } | 432 } |
436 | 433 |
437 #endif // defined(TARGET_OS_LINUX) | 434 #endif // defined(TARGET_OS_LINUX) |
OLD | NEW |