Skip to content

Commit 20a28c8

Browse files
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 9d992d3 commit 20a28c8

File tree

3 files changed

+2
-65
lines changed

3 files changed

+2
-65
lines changed

app/src/processing/app/Base.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,26 +2123,6 @@ static public void saveFile(String str, File file) throws IOException {
21232123
}
21242124

21252125

2126-
2127-
/**
2128-
* Remove all files in a directory and the directory itself.
2129-
*/
2130-
static public void removeDir(File dir) {
2131-
BaseNoGui.removeDir(dir);
2132-
}
2133-
2134-
2135-
/**
2136-
* Recursively remove all files within a directory,
2137-
* used with removeDir(), or when the contents of a dir
2138-
* should be removed, but not the directory itself.
2139-
* (i.e. when cleaning temp files from lib/build)
2140-
*/
2141-
static public void removeDescendants(File dir) {
2142-
BaseNoGui.removeDescendants(dir);
2143-
}
2144-
2145-
21462126
/**
21472127
* Calculate the size of the contents of a folder.
21482128
* Used to determine whether sketches are empty or not.

app/src/processing/app/SketchController.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ public void handleDeleteCode() throws IOException {
254254
// to do a save on the handleNew()
255255

256256
// delete the entire sketch
257-
Base.removeDir(sketch.getFolder());
257+
FileUtils.recursiveDelete(sketch.getFolder());
258258

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

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

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -991,49 +991,6 @@ static public void initParameters(String args[]) throws Exception {
991991
PreferencesData.init(absoluteFile(preferencesFile));
992992
}
993993

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

0 commit comments

Comments
 (0)