Skip to content

Commit 36fd0bf

Browse files
bitroncmaglie
authored andcommitted
Moved removeDescendants() and removeDir() from Base to BaseNoGui.
1 parent 7c58be3 commit 36fd0bf

File tree

3 files changed

+42
-26
lines changed

3 files changed

+42
-26
lines changed

app/src/processing/app/Base.java

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2604,12 +2604,7 @@ static public void copyDir(File sourceDir,
26042604
* Remove all files in a directory and the directory itself.
26052605
*/
26062606
static public void removeDir(File dir) {
2607-
if (dir.exists()) {
2608-
removeDescendants(dir);
2609-
if (!dir.delete()) {
2610-
System.err.println(I18n.format(_("Could not delete {0}"), dir));
2611-
}
2612-
}
2607+
BaseNoGui.removeDir(dir);
26132608
}
26142609

26152610

@@ -2620,24 +2615,7 @@ static public void removeDir(File dir) {
26202615
* (i.e. when cleaning temp files from lib/build)
26212616
*/
26222617
static public void removeDescendants(File dir) {
2623-
if (!dir.exists()) return;
2624-
2625-
String files[] = dir.list();
2626-
for (int i = 0; i < files.length; i++) {
2627-
if (files[i].equals(".") || files[i].equals("..")) continue;
2628-
File dead = new File(dir, files[i]);
2629-
if (!dead.isDirectory()) {
2630-
if (!Preferences.getBoolean("compiler.save_build_files")) {
2631-
if (!dead.delete()) {
2632-
// temporarily disabled
2633-
System.err.println(I18n.format(_("Could not delete {0}"), dead));
2634-
}
2635-
}
2636-
} else {
2637-
removeDir(dead);
2638-
//dead.delete();
2639-
}
2640-
}
2618+
BaseNoGui.removeDescendants(dir);
26412619
}
26422620

26432621

app/src/processing/app/BaseNoGui.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,45 @@ static public void prescanParameters(String args[]) {
391391
PreferencesData.init(absoluteFile(preferencesFile));
392392
}
393393

394+
/**
395+
* Recursively remove all files within a directory,
396+
* used with removeDir(), or when the contents of a dir
397+
* should be removed, but not the directory itself.
398+
* (i.e. when cleaning temp files from lib/build)
399+
*/
400+
static public void removeDescendants(File dir) {
401+
if (!dir.exists()) return;
402+
403+
String files[] = dir.list();
404+
for (int i = 0; i < files.length; i++) {
405+
if (files[i].equals(".") || files[i].equals("..")) continue;
406+
File dead = new File(dir, files[i]);
407+
if (!dead.isDirectory()) {
408+
if (!Preferences.getBoolean("compiler.save_build_files")) {
409+
if (!dead.delete()) {
410+
// temporarily disabled
411+
System.err.println(I18n.format(_("Could not delete {0}"), dead));
412+
}
413+
}
414+
} else {
415+
removeDir(dead);
416+
//dead.delete();
417+
}
418+
}
419+
}
420+
421+
/**
422+
* Remove all files in a directory and the directory itself.
423+
*/
424+
static public void removeDir(File dir) {
425+
if (dir.exists()) {
426+
removeDescendants(dir);
427+
if (!dir.delete()) {
428+
System.err.println(I18n.format(_("Could not delete {0}"), dir));
429+
}
430+
}
431+
}
432+
394433
/**
395434
* Spew the contents of a String object out to a file.
396435
*/

app/src/processing/app/debug/Compiler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
import java.util.SortedSet;
4040
import java.util.TreeSet;
4141

42-
import processing.app.Base;
4342
import processing.app.BaseNoGui;
4443
import processing.app.I18n;
4544
import processing.app.PreferencesData;
@@ -201,7 +200,7 @@ protected void cleanup(boolean force, File tempBuildFolder) {
201200
// the next time we start up, internal runs using Runner won't
202201
// work because the build dir won't exist at startup, so the classloader
203202
// will ignore the fact that that dir is in the CLASSPATH in run.sh
204-
Base.removeDescendants(tempBuildFolder);
203+
BaseNoGui.removeDescendants(tempBuildFolder);
205204
} else {
206205
// delete only stale source files, from the previously
207206
// compiled sketch. This allows multiple windows to be

0 commit comments

Comments
 (0)