Skip to content

Commit

Permalink
BFD-3279: Update recursivelyDelete to fix S2095 bug (#2197)
Browse files Browse the repository at this point in the history
Co-authored-by: Michael J Burling <[email protected]>
  • Loading branch information
aadedejifearless and mjburling authored Feb 14, 2024
1 parent 3872423 commit c0c872c
Showing 1 changed file with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Comparator;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import org.apache.commons.io.FileUtils;
Expand Down Expand Up @@ -174,12 +175,17 @@ public static void extractFile(ZipInputStream zipIn, Path filePath) throws IOExc
*/
private static void recursivelyDelete(Path tempDir) {
// Recursively delete the working dir.
try {
Files.walk(tempDir)
try (Stream<Path> paths = Files.walk(tempDir)) {
paths
.sorted(Comparator.reverseOrder())
.map(Path::toFile)
.peek(System.out::println)
.forEach(File::delete);
.forEach(
file -> {
if (!file.delete()) {
LOGGER.warn("Failed to delete file: " + file);
}
});
} catch (IOException e) {
LOGGER.warn("Failed to cleanup the temporary folder", e);
}
Expand Down

0 comments on commit c0c872c

Please sign in to comment.