Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,12 @@
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.file.FileVisitResult;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.SimpleFileVisitor;
import java.nio.file.attribute.BasicFileAttributes;
import java.time.Duration;
import java.time.Instant;
import java.util.ArrayList;
Expand Down Expand Up @@ -107,6 +110,13 @@ public void initialize(DBStore store, DBCheckpointMetrics metrics,
}
bootstrapTempData = Paths.get(tempData,
"temp-bootstrap-data").toFile();
if (bootstrapTempData.exists()) {
try {
deleteContents(bootstrapTempData.toPath());
} catch (IOException e) {
throw new ServletException(e);
}
}
if (!bootstrapTempData.exists() &&
!bootstrapTempData.mkdirs()) {
throw new ServletException("Failed to make:" + bootstrapTempData);
Expand All @@ -123,6 +133,24 @@ private boolean hasPermission(UserGroupInformation user) {
}
}

private void deleteContents(Path directory) throws IOException {
Files.walkFileTree(directory, new SimpleFileVisitor<Path>() {
@Override
public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
Files.delete(file); // Delete file
return FileVisitResult.CONTINUE;
}

@Override
public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
if (!dir.equals(directory)) { // Skip deleting the root directory
Files.delete(dir);
}
return FileVisitResult.CONTINUE;
}
});
}

/**
* Generates Snapshot checkpoint as tar ball.
* @param request the HTTP servlet request
Expand Down
Loading