You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@commons.apache.org by GitBox <gi...@apache.org> on 2021/11/01 14:44:39 UTC
[GitHub] [commons-io] garydgregory commented on a change in pull request #294: Update cleanDirectory(final File) method in org.apache.commons.io.FileUtils.
garydgregory commented on a change in pull request #294:
URL: https://github.com/apache/commons-io/pull/294#discussion_r740267789
##########
File path: src/main/java/org/apache/commons/io/FileUtils.java
##########
@@ -340,19 +340,26 @@ public static long checksumCRC32(final File file) throws IOException {
* @see #forceDelete(File)
*/
public static void cleanDirectory(final File directory) throws IOException {
- final File[] files = listFiles(directory, null);
-
- final List<Exception> causeList = new ArrayList<>();
- for (final File file : files) {
- try {
- forceDelete(file);
- } catch (final IOException ioe) {
- causeList.add(ioe);
- }
+ if (directory == null) {
+ return;
}
-
- if (!causeList.isEmpty()) {
- throw new IOExceptionList(directory.toString(), causeList);
+ if (directory.exists()) {
+ if (directory.isDirectory()) {
+ if (Objects.requireNonNull(directory.listFiles(), "File is not directory").length != 0) {
+ Arrays.stream(Objects.requireNonNull(directory.listFiles(), "File is not directory")).forEach(file -> {
+ try {
+ if (file.isDirectory() && Objects.requireNonNull(file.listFiles()).length != 0) {
+ cleanDirectory(file);
+ }
+ Files.delete(directory.toPath());
+ } catch (IOException e) {
+ e.printStackTrace();
Review comment:
Never output to the console.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: issues-unsubscribe@commons.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org