Skip to content

Commit f50f14b

Browse files
Review feedback.
1 parent 801a3b5 commit f50f14b

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

src/org/labkey/test/TestFileUtils.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import java.io.InputStream;
5757
import java.io.OutputStream;
5858
import java.io.OutputStreamWriter;
59+
import java.io.UncheckedIOException;
5960
import java.io.Writer;
6061
import java.nio.charset.Charset;
6162
import java.nio.charset.StandardCharsets;
@@ -469,18 +470,23 @@ public static void deleteDirWithRetry(File dir) throws Exception
469470
// Sometimes on Windows the directory could be locked, maybe by an external process, or the child directory is
470471
// readonly. Use a retry mechanism to set the writeable flag and then try to delete the parent directory.
471472
for (int attempt = 1; attempt <= 10; attempt++) {
472-
try {
473+
try
474+
{
473475
dir.setWritable(true, false);
474476

475477
// Wrap in a try to close the stream.
476-
try (Stream<Path> files = Files.walk(dir.toPath())) {
478+
try (Stream<Path> files = Files.walk(dir.toPath()))
479+
{
477480
files.forEach(p -> p.toFile().setWritable(true, false));
478481
}
479482

480483
FileUtils.deleteDirectory(dir);
481484
LOG.info(String.format("Deletion of directory %s was successful.", dir));
482485
break;
483-
} catch (IOException ioException) {
486+
} catch (AccessDeniedException e)
487+
{
488+
throw e;
489+
} catch (IOException | UncheckedIOException ioException) {
484490
LOG.warn(String.format("IOException trying to delete directory %s. Error: %s. Waiting 10s and retrying. Attempt %d of 10.",
485491
dir, ioException.getMessage(), attempt));
486492
if (attempt == 10) {
@@ -502,8 +508,6 @@ public static void deleteDirWithRetry(File dir) throws Exception
502508
LOG.info("Lock diagnostic...");
503509
pb.redirectErrorStream(true);
504510

505-
// Tried to use "try (Process p = pb.start()) {" without the finally block but our build
506-
// system didn't like that and complained that Process doesn't implement closeable (it does).
507511
Process p = pb.start();
508512
try (InputStream is = p.getInputStream()) {
509513
String output = new String(is.readAllBytes(), StringUtilsLabKey.DEFAULT_CHARSET);
@@ -515,7 +519,7 @@ public static void deleteDirWithRetry(File dir) throws Exception
515519
}
516520

517521
} catch (IOException diagnosticException) {
518-
LOG.warn("Failed to run lock diagnostic: " + diagnosticException);
522+
LOG.warn("Failed to run lock diagnostic: " + diagnosticException.getMessage(), diagnosticException);
519523
}
520524
throw ioException;
521525
}

0 commit comments

Comments
 (0)