Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(674)

Side by Side Diff: runtime/bin/directory_android.cc

Issue 2573143002: Handle non-regular files in recursive delete (Closed)
Patch Set: Address comments. Small adjustments Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | runtime/bin/directory_linux.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_ANDROID) 6 #if defined(TARGET_OS_ANDROID)
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 241 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 return path->Add(dir_name) && DeleteRecursively(path); 252 return path->Add(dir_name) && DeleteRecursively(path);
253 } 253 }
254 254
255 255
256 static bool DeleteRecursively(PathBuffer* path) { 256 static bool DeleteRecursively(PathBuffer* path) {
257 // Do not recurse into links for deletion. Instead delete the link. 257 // Do not recurse into links for deletion. Instead delete the link.
258 // If it's a file, delete it. 258 // If it's a file, delete it.
259 struct stat st; 259 struct stat st;
260 if (NO_RETRY_EXPECTED(lstat(path->AsString(), &st)) == -1) { 260 if (NO_RETRY_EXPECTED(lstat(path->AsString(), &st)) == -1) {
261 return false; 261 return false;
262 } else if (S_ISREG(st.st_mode) || S_ISLNK(st.st_mode)) { 262 } else if (!S_ISDIR(st.st_mode)) {
263 return (unlink(path->AsString()) == 0); 263 return (unlink(path->AsString()) == 0);
264 } 264 }
265 265
266 if (!path->Add(File::PathSeparator())) { 266 if (!path->Add(File::PathSeparator())) {
267 return false; 267 return false;
268 } 268 }
269 269
270 // Not a link. Attempt to open as a directory and recurse into the 270 // Not a link. Attempt to open as a directory and recurse into the
271 // directory. 271 // directory.
272 DIR* dir_pointer; 272 DIR* dir_pointer;
(...skipping 12 matching lines...) Expand all
285 if (result == NULL) { 285 if (result == NULL) {
286 // End of directory. 286 // End of directory.
287 return NO_RETRY_EXPECTED(closedir(dir_pointer)) == 0 && 287 return NO_RETRY_EXPECTED(closedir(dir_pointer)) == 0 &&
288 NO_RETRY_EXPECTED(remove(path->AsString())) == 0; 288 NO_RETRY_EXPECTED(remove(path->AsString())) == 0;
289 } 289 }
290 bool ok = false; 290 bool ok = false;
291 switch (entry.d_type) { 291 switch (entry.d_type) {
292 case DT_DIR: 292 case DT_DIR:
293 ok = DeleteDir(entry.d_name, path); 293 ok = DeleteDir(entry.d_name, path);
294 break; 294 break;
295 case DT_BLK:
296 case DT_CHR:
297 case DT_FIFO:
298 case DT_SOCK:
295 case DT_REG: 299 case DT_REG:
296 case DT_LNK: 300 case DT_LNK:
297 // Treat all links as files. This will delete the link which 301 // Treat all links as files. This will delete the link which
298 // is what we want no matter if the link target is a file or a 302 // is what we want no matter if the link target is a file or a
299 // directory. 303 // directory.
300 ok = DeleteFile(entry.d_name, path); 304 ok = DeleteFile(entry.d_name, path);
301 break; 305 break;
302 case DT_UNKNOWN: { 306 case DT_UNKNOWN: {
303 if (!path->Add(entry.d_name)) { 307 if (!path->Add(entry.d_name)) {
304 break; 308 break;
305 } 309 }
306 // On some file systems the entry type is not determined by 310 // On some file systems the entry type is not determined by
307 // readdir_r. For those we use lstat to determine the entry 311 // readdir_r. For those we use lstat to determine the entry
308 // type. 312 // type.
309 struct stat entry_info; 313 struct stat entry_info;
310 if (NO_RETRY_EXPECTED(lstat(path->AsString(), &entry_info)) == -1) { 314 if (NO_RETRY_EXPECTED(lstat(path->AsString(), &entry_info)) == -1) {
311 break; 315 break;
312 } 316 }
313 path->Reset(path_length); 317 path->Reset(path_length);
314 if (S_ISDIR(entry_info.st_mode)) { 318 if (S_ISDIR(entry_info.st_mode)) {
315 ok = DeleteDir(entry.d_name, path); 319 ok = DeleteDir(entry.d_name, path);
316 } else if (S_ISREG(entry_info.st_mode) || S_ISLNK(entry_info.st_mode)) { 320 } else {
317 // Treat links as files. This will delete the link which is 321 // Treat links as files. This will delete the link which is
318 // what we want no matter if the link target is a file or a 322 // what we want no matter if the link target is a file or a
319 // directory. 323 // directory.
320 ok = DeleteFile(entry.d_name, path); 324 ok = DeleteFile(entry.d_name, path);
321 } 325 }
322 break; 326 break;
323 } 327 }
324 default: 328 default:
329 // We should have covered all the bases. If not, let's get an error.
330 FATAL1("Unexpected d_type: %d\n", entry.d_type);
325 break; 331 break;
326 } 332 }
327 if (!ok) { 333 if (!ok) {
328 break; 334 break;
329 } 335 }
330 path->Reset(path_length); 336 path->Reset(path_length);
331 } 337 }
332 // Only happens if an error. 338 // Only happens if an error.
333 ASSERT(errno != 0); 339 ASSERT(errno != 0);
334 int err = errno; 340 int err = errno;
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
467 if (exists != EXISTS) { 473 if (exists != EXISTS) {
468 return false; 474 return false;
469 } 475 }
470 return (NO_RETRY_EXPECTED(rename(path, new_path)) == 0); 476 return (NO_RETRY_EXPECTED(rename(path, new_path)) == 0);
471 } 477 }
472 478
473 } // namespace bin 479 } // namespace bin
474 } // namespace dart 480 } // namespace dart
475 481
476 #endif // defined(TARGET_OS_ANDROID) 482 #endif // defined(TARGET_OS_ANDROID)
OLDNEW
« no previous file with comments | « no previous file | runtime/bin/directory_linux.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698