- /** Delete empty parent directory up to the A2 target (included). */
- void deleteEmptyParents(Path targetA2, Path targetParent) throws IOException {
+ /** Delete empty parent directory up to the base directory (included). */
+ void deleteEmptyParents(Path baseDir, Path targetParent) throws IOException {
+ if (!targetParent.startsWith(baseDir))
+ throw new IllegalArgumentException(targetParent + " does not start with " + baseDir);
+ if (!Files.exists(baseDir))
+ return;
+ if (!Files.exists(targetParent)) {
+ deleteEmptyParents(baseDir, targetParent.getParent());
+ return;
+ }