- private static void uncheckedDeleteAll(Path path) {
- try {
- FileUtils.deleteAll(path.toFile());
- } catch (IOException e) {
- throw new RuntimeIOException(e);
+ private static void deleteAll(Path dir) throws IOException {
+ Files.walkFileTree(dir, new SimpleFileVisitor<Path>() {
+ @Override
+ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
+ Files.delete(file);
+ return FileVisitResult.CONTINUE;
+ }
+ @Override
+ public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
+ Files.delete(dir);
+ return FileVisitResult.CONTINUE;
+ }
+ });
+ }
+
+ private static final DateTimeFormatter RECOVERY_DIR_FORMAT = DateTimeFormatter.ofPattern("yyyy-M-d_HH-mm-ss");
+
+ private static Path getRecoveryFolder(Path directory) {
+ return findNonexistentDir(
+ directory.resolve("recovery"),
+ RECOVERY_DIR_FORMAT.format(ZonedDateTime.now()));
+ }
+
+ private static Path findNonexistentDir(Path inDirectory, String prefix) {
+ for (int i = 0;; ++i) {
+ Path dir = inDirectory.resolve(i == 0 ? prefix : prefix + "-" + i);
+ if (Files.notExists(dir))
+ return dir;