Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve robustness of removing invalid clones #420

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -103,25 +103,44 @@ private NewClone fetchRef(Repository repository) throws IOException {
return new NewClone(repository, fetchHead);
}

private void removeOldClone(Path path, String reason) {
if (!Files.exists(seed)) {
try {
Files.createDirectories(seed.getParent());
} catch (IOException e) {
log.severe("Failed to create seed parent folder: " + seed.getParent());
log.throwing("HostedRepositoryInstance", "preserveOldClone", e);
}
}
var preserved = seed.resolveSibling(seed.getFileName().toString() + "-" + reason + "-" + UUID.randomUUID());
log.severe("Invalid local repository detected (" + reason + ") - preserved in: " + preserved);
try {
Files.move(path, preserved);
} catch (IOException e) {
log.severe("Failed to preserve old clone at " + path);
log.throwing("HostedRepositoryInstance", "preserveOldClone", e);
} finally {
if (Files.exists(path)) {
clearDirectory(path);
}
}
}

private NewClone materializeClone(Path path) throws IOException {
var localRepo = Repository.get(path);
if (localRepo.isEmpty()) {
return fetchRef(cloneSeeded(path));
} else {
var localRepoInstance = localRepo.get();
if (!localRepoInstance.isHealthy()) {
var preserveUnhealthy = seed.resolveSibling(seed.getFileName().toString() + "-unhealthy-" + UUID.randomUUID());
log.severe("Unhealthy local repository detected - preserved in: " + preserveUnhealthy);
Files.move(path, preserveUnhealthy);
removeOldClone(path, "unhealthy");
return fetchRef(cloneSeeded(path));
} else {
try {
localRepoInstance.clean();
return fetchRef(localRepoInstance);
} catch (IOException e) {
var preserveUnclean = seed.resolveSibling(seed.getFileName().toString() + "-unclean-" + UUID.randomUUID());
log.severe("Uncleanable local repository detected - preserved in: " + preserveUnclean);
Files.move(path, preserveUnclean);
removeOldClone(path, "uncleanable");
return fetchRef(cloneSeeded(path));
}
}