Skip to content

Commit

Permalink
Deprecate TestUtil.deleteRecursively (#1315)
Browse files Browse the repository at this point in the history
* It has been replaced by IOUtil.recursiveDelete()
  • Loading branch information
lbergelson authored Mar 7, 2019
1 parent 68199fb commit dd313de
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
15 changes: 10 additions & 5 deletions src/main/java/htsjdk/samtools/util/IOUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -1318,27 +1318,32 @@ private static String stripQueryStringIfPathIsAnHttpUrl(String path) {
}

/**
* Little test utility to help tests that create multiple levels of subdirectories
* clean up after themselves.
* Delete a directory and all files in it.
*
* @param directory The directory to be deleted (along with its subdirectories)
*/
public static void recursiveDelete(final Path directory) throws IOException {

public static void recursiveDelete(final Path directory) {
final SimpleFileVisitor<Path> simpleFileVisitor = new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
super.visitFile(file, attrs);
Files.deleteIfExists(file);
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
super.postVisitDirectory(dir, exc);
Files.deleteIfExists(dir);
return FileVisitResult.CONTINUE;
}
};

Files.walkFileTree(directory, simpleFileVisitor);
try {
Files.walkFileTree(directory, simpleFileVisitor);
} catch (final IOException e){
throw new RuntimeIOException(e);
}
}
}
4 changes: 3 additions & 1 deletion src/main/java/htsjdk/samtools/util/TestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ public static <T extends Serializable> T serializeAndDeserialize(T input) throws
* clean up after themselves.
*
* @param directory The directory to be deleted (along with its subdirectories)
* @deprecated Since 3/19, prefer {@link IOUtil#recursiveDelete(Path)}
*/
@Deprecated
public static void recursiveDelete(final File directory) {
try {
IOUtil.recursiveDelete(directory.toPath());
} catch (IOException e) {
} catch (RuntimeIOException e) {
// bury exception
}
}
Expand Down

0 comments on commit dd313de

Please sign in to comment.