Skip to content

Commit c0f41ca

Browse files
matthijskooijmanfacchinm
authored andcommitted
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.
1 parent 72f815b commit c0f41ca

File tree

3 files changed

+2
-65
lines changed

3 files changed

+2
-65
lines changed

app/src/processing/app/Base.java

-20
Original file line numberDiff line numberDiff line change
@@ -2091,26 +2091,6 @@ static public void saveFile(String str, File file) throws IOException {
20912091
}
20922092

20932093

2094-
2095-
/**
2096-
* Remove all files in a directory and the directory itself.
2097-
*/
2098-
static public void removeDir(File dir) {
2099-
BaseNoGui.removeDir(dir);
2100-
}
2101-
2102-
2103-
/**
2104-
* Recursively remove all files within a directory,
2105-
* used with removeDir(), or when the contents of a dir
2106-
* should be removed, but not the directory itself.
2107-
* (i.e. when cleaning temp files from lib/build)
2108-
*/
2109-
static public void removeDescendants(File dir) {
2110-
BaseNoGui.removeDescendants(dir);
2111-
}
2112-
2113-
21142094
/**
21152095
* Calculate the size of the contents of a folder.
21162096
* Used to determine whether sketches are empty or not.

app/src/processing/app/SketchController.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ public void handleDeleteCode() throws IOException {
253253
// to do a save on the handleNew()
254254

255255
// delete the entire sketch
256-
Base.removeDir(sketch.getFolder());
256+
FileUtils.recursiveDelete(sketch.getFolder());
257257

258258
// get the changes into the sketchbook menu
259259
//sketchbook.rebuildMenus();
@@ -419,7 +419,7 @@ protected boolean saveAs() throws IOException {
419419
// its contents before copying everything over
420420
// (user will have already been warned)
421421
if (newFolder.exists()) {
422-
Base.removeDir(newFolder);
422+
FileUtils.recursiveDelete(newFolder);
423423
}
424424
// in fact, you can't do this on windows because the file dialog
425425
// will instead put you inside the folder, but it happens on osx a lot.

arduino-core/src/processing/app/BaseNoGui.java

-43
Original file line numberDiff line numberDiff line change
@@ -1000,49 +1000,6 @@ static public void initParameters(String args[]) throws Exception {
10001000
PreferencesData.init(absoluteFile(preferencesFile));
10011001
}
10021002

1003-
/**
1004-
* Recursively remove all files within a directory,
1005-
* used with removeDir(), or when the contents of a dir
1006-
* should be removed, but not the directory itself.
1007-
* (i.e. when cleaning temp files from lib/build)
1008-
*/
1009-
static public void removeDescendants(File dir) {
1010-
if (!dir.exists()) return;
1011-
1012-
String files[] = dir.list();
1013-
if (files == null) {
1014-
return;
1015-
}
1016-
1017-
for (String file : files) {
1018-
if (file.equals(".") || file.equals("..")) continue;
1019-
File dead = new File(dir, file);
1020-
if (!dead.isDirectory()) {
1021-
if (!PreferencesData.getBoolean("compiler.save_build_files")) {
1022-
if (!dead.delete()) {
1023-
// temporarily disabled
1024-
System.err.println(I18n.format(tr("Could not delete {0}"), dead));
1025-
}
1026-
}
1027-
} else {
1028-
removeDir(dead);
1029-
//dead.delete();
1030-
}
1031-
}
1032-
}
1033-
1034-
/**
1035-
* Remove all files in a directory and the directory itself.
1036-
*/
1037-
static public void removeDir(File dir) {
1038-
if (dir.exists()) {
1039-
removeDescendants(dir);
1040-
if (!dir.delete()) {
1041-
System.err.println(I18n.format(tr("Could not delete {0}"), dir));
1042-
}
1043-
}
1044-
}
1045-
10461003
/**
10471004
* Produce a sanitized name that fits our standards for likely to work.
10481005
* <p/>

0 commit comments

Comments
 (0)