diff options
author | Xavier Ducrohet <xav@android.com> | 2010-01-11 17:01:05 -0800 |
---|---|---|
committer | Xavier Ducrohet <xav@android.com> | 2010-01-11 18:24:13 -0800 |
commit | 0d0fcc50842d0db182105ebee2fc60618fcacd28 (patch) | |
tree | 1a9b43958fe09400fc65b572d12a4b60a258aed6 | |
parent | 18ab12550ad8ebc2791f6a40bbd985ad9a93ac10 (diff) | |
download | sdk-0d0fcc50842d0db182105ebee2fc60618fcacd28.zip sdk-0d0fcc50842d0db182105ebee2fc60618fcacd28.tar.gz sdk-0d0fcc50842d0db182105ebee2fc60618fcacd28.tar.bz2 |
AVD Mananger: Fix the deletion of a folder content.
Bug: 2364917
Change-Id: I9585200adad5deb2ef27ea157ddd25e7124c2e73
-rw-r--r-- | sdkmanager/libs/sdklib/src/com/android/sdklib/internal/avd/AvdManager.java | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/avd/AvdManager.java b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/avd/AvdManager.java index 9499798..0713e74 100644 --- a/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/avd/AvdManager.java +++ b/sdkmanager/libs/sdklib/src/com/android/sdklib/internal/avd/AvdManager.java @@ -487,7 +487,11 @@ public final class AvdManager { if (removePrevious) { // AVD already exists and removePrevious is set, try to remove the // directory's content first (but not the directory itself). - recursiveDelete(avdFolder); + try { + deleteContentOf(avdFolder); + } catch (SecurityException e) { + log.error(e, "Failed to delete %1$s", avdFolder.getAbsolutePath()); + } } else { // AVD shouldn't already exist if removePrevious is false. log.error(null, @@ -712,8 +716,12 @@ public final class AvdManager { log.warning("Removing previous AVD directory at %s", oldAvdInfo.getPath()); // Remove the old data directory File dir = new File(oldAvdInfo.getPath()); - recursiveDelete(dir); - dir.delete(); + try { + deleteContentOf(dir); + dir.delete(); + } catch (SecurityException e) { + log.error(e, "Failed to delete %1$s", dir.getAbsolutePath()); + } } return newAvdInfo; @@ -721,14 +729,20 @@ public final class AvdManager { log.error(e, null); } catch (IOException e) { log.error(e, null); + } catch (SecurityException e) { + log.error(e, null); } finally { if (needCleanup) { if (iniFile != null && iniFile.exists()) { iniFile.delete(); } - recursiveDelete(avdFolder); - avdFolder.delete(); + try { + deleteContentOf(avdFolder); + avdFolder.delete(); + } catch (SecurityException e) { + log.error(e, "Failed to delete %1$s", avdFolder.getAbsolutePath()); + } } } @@ -896,8 +910,7 @@ public final class AvdManager { f = new File(path); if (f.exists()) { log.printf("Deleting folder %1$s\n", f.getCanonicalPath()); - recursiveDelete(f); - if (!f.delete()) { + if (deleteContentOf(f) == false || f.delete() == false) { log.error(null, "Failed to delete %1$s\n", f.getCanonicalPath()); error = true; } @@ -918,6 +931,8 @@ public final class AvdManager { log.error(e, null); } catch (IOException e) { log.error(e, null); + } catch (SecurityException e) { + log.error(e, null); } return false; } @@ -991,13 +1006,20 @@ public final class AvdManager { * * @throws SecurityException like {@link File#delete()} does if file/folder is not writable. */ - public void recursiveDelete(File folder) { + private boolean deleteContentOf(File folder) throws SecurityException { for (File f : folder.listFiles()) { if (f.isDirectory()) { - recursiveDelete(folder); + if (deleteContentOf(f) == false) { + return false; + } + } + if (f.delete() == false) { + return false; } - f.delete(); + } + + return true; } /** |