[ 
https://issues.apache.org/jira/browse/IO-596?focusedWorklogId=178866&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-178866
 ]

ASF GitHub Bot logged work on IO-596:
-------------------------------------

                Author: ASF GitHub Bot
            Created on: 27/Dec/18 02:31
            Start Date: 27/Dec/18 02:31
    Worklog Time Spent: 10m 
      Work Description: asciborek commented on pull request #72: [IO-596] Add 
DeleteFiles utility class
URL: https://github.com/apache/commons-io/pull/72#discussion_r244072727
 
 

 ##########
 File path: src/main/java/org/apache/commons/io/DeleteFiles.java
 ##########
 @@ -0,0 +1,339 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.io;
+
+import java.io.IOException;
+import java.nio.file.DirectoryStream;
+import java.nio.file.Files;
+import java.nio.file.LinkOption;
+import java.nio.file.Path;
+import java.nio.file.attribute.PosixFileAttributeView;
+import java.nio.file.attribute.PosixFilePermission;
+import java.util.ArrayList;
+import java.util.EnumSet;
+import java.util.List;
+import java.util.Set;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * Provides different strategies to delete files and directories.
+ */
+public final class DeleteFiles {
+
+    private static final DeleteFiles DEFAULT = newConfig().build();
+
+    /**
+     * Gets the default DeleteFiles strategy.
+     */
+    public static DeleteFiles getDefault() {
+        return DEFAULT;
+    }
+
+    /**
+     * Creates a new Config builder object to override options in DeleteFiles.
+     */
+    public static Config newConfig() {
+        return new Config();
+    }
+
+    private final int maxRetries;
+    private final long waitBetweenRetriesMillis;
+    private final double backoffMultiplier;
+    private final boolean retryOverridingFileAttributes;
+    private final boolean overrideAllAttributes;
+
+    private DeleteFiles(final int maxRetries, final long 
waitBetweenRetriesMillis, final double backoffMultiplier,
+                        final boolean retryOverridingFileAttributes, final 
boolean overrideAllAttributes) {
+        this.maxRetries = maxRetries;
+        this.waitBetweenRetriesMillis = waitBetweenRetriesMillis;
+        this.backoffMultiplier = backoffMultiplier;
+        this.retryOverridingFileAttributes = retryOverridingFileAttributes;
+        this.overrideAllAttributes = overrideAllAttributes;
+    }
+
+    /**
+     * Deletes a file or directory and its contents recursively.
+     *
+     * @param path path to delete
+     * @throws IOException if there is an error deleting anything
+     */
+    public void forceDelete(final Path path) throws IOException {
+        final List<IOException> accumulatedErrors = new ArrayList<>();
+        for (int retriesAttempted = 0; retriesAttempted <= maxRetries; 
retriesAttempted++) {
+            final List<IOException> errors = tryDeleteRecursive(path);
+            if (errors.isEmpty()) {
+                return;
+            }
+            accumulatedErrors.addAll(errors);
+            if (waitToRetry(retriesAttempted)) {
+                throw new CompositeIOException(failureMessage(path, 
retriesAttempted, true), accumulatedErrors);
+            }
+        }
+        throw new CompositeIOException(failureMessage(path, maxRetries, 
false), accumulatedErrors);
 
 Review comment:
   From what I can see this code will always cause throwing a new exception
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


Issue Time Tracking
-------------------

    Worklog Id:     (was: 178866)
    Time Spent: 0.5h  (was: 20m)

> Add DeleteFiles utility class for more robust file deletion strategies
> ----------------------------------------------------------------------
>
>                 Key: IO-596
>                 URL: https://issues.apache.org/jira/browse/IO-596
>             Project: Commons IO
>          Issue Type: New Feature
>          Components: Utilities
>            Reporter: Matt Sicker
>            Assignee: Matt Sicker
>            Priority: Major
>          Time Spent: 0.5h
>  Remaining Estimate: 0h
>
> Particularly for Windows environments where deleting files can turn into a 
> hassle due to the inability to remove open files, I would like to provide a 
> file deletion utility class that has the ability to retry deletions with 
> exponential backoff, force override file attributes to allow for deletion, 
> and deleting as much as possible while accumulating errors.
> This functionality was originally inspired by and based on functionality in 
> Jenkins hudson.Util class.



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to