This is the codeAbility Sharing Platform! Learn more about the codeAbility Sharing Platform.

Skip to content
Snippets Groups Projects
Commit f09c605e authored by Daniel Crazzolara's avatar Daniel Crazzolara
Browse files

Improved file handling in case of errors

parent 079581a9
Branches
Tags
2 merge requests!62created achievementService and separated some functionality out of...,!61Feature/#51 import from artemis
......@@ -89,7 +89,11 @@ public class ExerciseService {
}
gitlabService.commitAndPushToRepo(repo, new File("tmp-import", exerciseToken));
FileUtils.deleteDirectory(new File("tmp-import", exerciseToken));
try {
FileUtils.deleteDirectory(new File("tmp-import", exerciseToken));
} catch (IOException e) {
log.error("Could not remove directory: {} \n", e.getMessage());
}
}
/**
......
......@@ -223,10 +223,15 @@ public class GitlabService {
git.push().setCredentialsProvider(CredentialsProvider.getDefault()).call();
} catch (GitLabApiException | GitAPIException e) {
if (git.getRepository().getDirectory().getParentFile().exists()) {
FileUtils.deleteDirectory(git.getRepository().getDirectory().getParentFile());
try {
FileUtils.deleteDirectory(git.getRepository().getDirectory().getParentFile());
} catch (IOException ioe) {
log.error("Could not remove directory: {} \n", ioe.getMessage());
}
}
log.error("An error occurred during the commit and push of files: {}", e.getMessage());
throw e;
git.close();
throw e;
}
git.close();
}
......@@ -241,7 +246,18 @@ public class GitlabService {
File dst = new File("tmp-import", repoDirName);
if (dst.exists()) {
log.debug("Temporary directory '{}' already exists, removing it.", dst.getPath());
FileUtils.deleteDirectory(dst);
try {
FileUtils.deleteDirectory(dst);
} catch (IOException e) {
log.error("Unable to remove directory. Trying to rename it.. : {} \n", e.getMessage());
try {
if (dst.renameTo(new File("delete_me", dst.getName()))) {
log.error("Unable to rename directory. Trying to overwrite it..");
}
} catch (SecurityException se) {
log.error("Unable to rename directory. Trying to overwrite it.. : {}", se.getMessage());
}
}
}
try {
Git git = Git.cloneRepository().setURI(repoUrl).setDirectory(dst).call();
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment