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 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
294 } | 294 } |
295 // End of directory. | 295 // End of directory. |
296 return (NO_RETRY_EXPECTED(closedir(dir_pointer)) == 0) && | 296 return (NO_RETRY_EXPECTED(closedir(dir_pointer)) == 0) && |
297 (NO_RETRY_EXPECTED(remove(path->AsString())) == 0); | 297 (NO_RETRY_EXPECTED(remove(path->AsString())) == 0); |
298 } | 298 } |
299 bool ok = false; | 299 bool ok = false; |
300 switch (entry->d_type) { | 300 switch (entry->d_type) { |
301 case DT_DIR: | 301 case DT_DIR: |
302 ok = DeleteDir(entry->d_name, path); | 302 ok = DeleteDir(entry->d_name, path); |
303 break; | 303 break; |
304 case DT_BLK: | |
305 case DT_CHR: | |
306 case DT_FIFO: | |
307 case DT_SOCK: | |
304 case DT_REG: | 308 case DT_REG: |
305 case DT_LNK: | 309 case DT_LNK: |
306 // Treat all links as files. This will delete the link which | 310 // Treat all links as files. This will delete the link which |
307 // is what we want no matter if the link target is a file or a | 311 // is what we want no matter if the link target is a file or a |
308 // directory. | 312 // directory. |
309 ok = DeleteFile(entry->d_name, path); | 313 ok = DeleteFile(entry->d_name, path); |
310 break; | 314 break; |
311 case DT_UNKNOWN: { | 315 case DT_UNKNOWN: { |
312 if (!path->Add(entry->d_name)) { | 316 if (!path->Add(entry->d_name)) { |
313 break; | 317 break; |
314 } | 318 } |
315 // On some file systems the entry type is not determined by | 319 // On some file systems the entry type is not determined by |
316 // readdir. For those we use lstat to determine the entry | 320 // readdir. For those we use lstat to determine the entry |
317 // type. | 321 // type. |
318 struct stat64 entry_info; | 322 struct stat64 entry_info; |
319 if (TEMP_FAILURE_RETRY(lstat64(path->AsString(), &entry_info)) == -1) { | 323 if (TEMP_FAILURE_RETRY(lstat64(path->AsString(), &entry_info)) == -1) { |
320 break; | 324 break; |
321 } | 325 } |
322 path->Reset(path_length); | 326 path->Reset(path_length); |
323 if (S_ISDIR(entry_info.st_mode)) { | 327 if (S_ISDIR(entry_info.st_mode)) { |
324 ok = DeleteDir(entry->d_name, path); | 328 ok = DeleteDir(entry->d_name, path); |
325 } else if (S_ISREG(entry_info.st_mode) || S_ISLNK(entry_info.st_mode)) { | 329 } else if (S_ISREG(entry_info.st_mode) || S_ISCHR(entry_info.st_mode) || |
rmacnak
2016/12/14 18:44:02
Keep S_ISLNK
zra
2016/12/14 20:48:07
Done.
| |
330 S_ISBLK(entry_info.st_mode) || | |
331 S_ISFIFO(entry_info.st_mode) || | |
332 S_ISSOCK(entry_info.st_mode)) { | |
326 // Treat links as files. This will delete the link which is | 333 // Treat links as files. This will delete the link which is |
327 // what we want no matter if the link target is a file or a | 334 // what we want no matter if the link target is a file or a |
328 // directory. | 335 // directory. |
329 ok = DeleteFile(entry->d_name, path); | 336 ok = DeleteFile(entry->d_name, path); |
337 } else { | |
338 FATAL1("Unexpected st_mode: %d\n", entry_info.st_mode); | |
330 } | 339 } |
331 break; | 340 break; |
332 } | 341 } |
333 default: | 342 default: |
343 // We should have covered all the bases. If not, let's get an error. | |
344 FATAL1("Unexpected d_type: %d\n", entry->d_type); | |
334 break; | 345 break; |
335 } | 346 } |
336 if (!ok) { | 347 if (!ok) { |
337 break; | 348 break; |
338 } | 349 } |
339 path->Reset(path_length); | 350 path->Reset(path_length); |
340 } | 351 } |
341 // Only happens if an error. | 352 // Only happens if an error. |
342 ASSERT(errno != 0); | 353 ASSERT(errno != 0); |
343 int err = errno; | 354 int err = errno; |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
471 if (exists != EXISTS) { | 482 if (exists != EXISTS) { |
472 return false; | 483 return false; |
473 } | 484 } |
474 return (NO_RETRY_EXPECTED(rename(path, new_path)) == 0); | 485 return (NO_RETRY_EXPECTED(rename(path, new_path)) == 0); |
475 } | 486 } |
476 | 487 |
477 } // namespace bin | 488 } // namespace bin |
478 } // namespace dart | 489 } // namespace dart |
479 | 490 |
480 #endif // defined(TARGET_OS_LINUX) | 491 #endif // defined(TARGET_OS_LINUX) |
OLD | NEW |