Remove `Base.removeDir()` and `Base.removeDescendants()`

These methods shouldn't really be in Base (or BaseNoGui, which did the
actual work), especially since there is already a
`FileUtils.recursiveDelete()` which just does the same thing. This
commit removes the code from Base and BaseNoGui and instead uses the
method from FileUtils.

There is one difference between these methods: the Base methods did not
delete files if the "compiler.save_build_files" preference was set.
However, the Base methods were only used when deleting a sketch, or
deleting an existing folder before overwriting it on save as, so this
preference didn't actually do what it was supposed to anyway, so
dropping it shouldn't be a problem.
This commit is contained in:
Matthijs Kooijman 2015-12-29 16:31:31 +01:00 committed by Martino Facchin
parent 72f815bcf9
commit c0f41cae5d
3 changed files with 2 additions and 65 deletions

View File

@ -2091,26 +2091,6 @@ public class Base {
}
/**
* Remove all files in a directory and the directory itself.
*/
static public void removeDir(File dir) {
BaseNoGui.removeDir(dir);
}
/**
* Recursively remove all files within a directory,
* used with removeDir(), or when the contents of a dir
* should be removed, but not the directory itself.
* (i.e. when cleaning temp files from lib/build)
*/
static public void removeDescendants(File dir) {
BaseNoGui.removeDescendants(dir);
}
/**
* Calculate the size of the contents of a folder.
* Used to determine whether sketches are empty or not.

View File

@ -253,7 +253,7 @@ public class SketchController {
// to do a save on the handleNew()
// delete the entire sketch
Base.removeDir(sketch.getFolder());
FileUtils.recursiveDelete(sketch.getFolder());
// get the changes into the sketchbook menu
//sketchbook.rebuildMenus();
@ -419,7 +419,7 @@ public class SketchController {
// its contents before copying everything over
// (user will have already been warned)
if (newFolder.exists()) {
Base.removeDir(newFolder);
FileUtils.recursiveDelete(newFolder);
}
// in fact, you can't do this on windows because the file dialog
// will instead put you inside the folder, but it happens on osx a lot.

View File

@ -1000,49 +1000,6 @@ public class BaseNoGui {
PreferencesData.init(absoluteFile(preferencesFile));
}
/**
* Recursively remove all files within a directory,
* used with removeDir(), or when the contents of a dir
* should be removed, but not the directory itself.
* (i.e. when cleaning temp files from lib/build)
*/
static public void removeDescendants(File dir) {
if (!dir.exists()) return;
String files[] = dir.list();
if (files == null) {
return;
}
for (String file : files) {
if (file.equals(".") || file.equals("..")) continue;
File dead = new File(dir, file);
if (!dead.isDirectory()) {
if (!PreferencesData.getBoolean("compiler.save_build_files")) {
if (!dead.delete()) {
// temporarily disabled
System.err.println(I18n.format(tr("Could not delete {0}"), dead));
}
}
} else {
removeDir(dead);
//dead.delete();
}
}
}
/**
* Remove all files in a directory and the directory itself.
*/
static public void removeDir(File dir) {
if (dir.exists()) {
removeDescendants(dir);
if (!dir.delete()) {
System.err.println(I18n.format(tr("Could not delete {0}"), dir));
}
}
}
/**
* Produce a sanitized name that fits our standards for likely to work.
* <p/>