| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent 72d92a2 commit 350bb2f
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -23,6 +23,8 @@ | |||
| 23 | 23 | package processing.app; | |
| 24 | 24 | ||
| 25 | 25 | import java.io.*; | |
| 26 | + import java.nio.file.Files; | ||
| 27 | + import java.nio.file.Path; | ||
| 26 | 28 | import java.util.Enumeration; | |
| 27 | 29 | import java.util.Vector; | |
| 28 | 30 | import java.util.zip.*; | |
@@ -301,7 +303,7 @@ static public void copyDirNative(File sourceDir, | |||
| 301 | 303 | ||
| 302 | 304 | /** | |
| 303 | 305 | * Remove all files in a directory and the directory itself. | |
| 304 | - * Prints error messages with failed filenames. | ||
| 306 | + * Prints error messages with failed filenames. Does not follow symlinks. | ||
| 305 | 307 | */ | |
| 306 | 308 | static public boolean removeDir(File dir) { | |
| 307 | 309 | return removeDir(dir, true); | |
@@ -310,22 +312,25 @@ static public boolean removeDir(File dir) { | |||
| 310 | 312 | /** | |
| 311 | 313 | * Remove all files in a directory and the directory itself. | |
| 312 | 314 | * Optinally prints error messages with failed filenames. | |
| 315 | + * Does not follow symlinks. | ||
| 313 | 316 | */ | |
| 314 | 317 | static public boolean removeDir(File dir, boolean printErrorMessages) { | |
| 315 | 318 | if (!dir.exists()) return true; | |
| 316 | 319 | ||
| 317 | 320 | boolean result = true; | |
| 318 | - File[] files = dir.listFiles(); | ||
| 319 | - if (files != null) { | ||
| 320 | - for (File child : files) { | ||
| 321 | - if (child.isFile()) { | ||
| 322 | - boolean deleted = child.delete(); | ||
| 323 | - if (!deleted && printErrorMessages) { | ||
| 324 | - System.err.println("Could not delete " + child.getAbsolutePath()); | ||
| 321 | + if (!Files.isSymbolicLink(dir.toPath())) { | ||
| 322 | + File[] files = dir.listFiles(); | ||
| 323 | + if (files != null) { | ||
| 324 | + for (File child : files) { | ||
| 325 | + if (child.isFile()) { | ||
| 326 | + boolean deleted = child.delete(); | ||
| 327 | + if (!deleted && printErrorMessages) { | ||
| 328 | + System.err.println("Could not delete " + child.getAbsolutePath()); | ||
| 329 | + } | ||
| 330 | + result &= deleted; | ||
| 331 | + } else if (child.isDirectory()) { | ||
| 332 | + result &= removeDir(child, printErrorMessages); | ||
| 325 | 333 | } | |
| 326 | - result &= deleted; | ||
| 327 | - } else if (child.isDirectory()) { | ||
| 328 | - result &= removeDir(child, printErrorMessages); | ||
| 329 | 334 | } | |
| 330 | 335 | } | |
| 331 | 336 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments