Try to fix VersionNotFoundException. Closes #298

This commit is contained in:
huangyuhui
2018-06-08 16:03:43 +08:00
parent 110b7cb06f
commit 37a39098f8

View File

@@ -155,8 +155,26 @@ public class DefaultGameRepository implements GameRepository {
File file = getVersionRoot(id);
if (!file.exists())
return true;
// test if no file in this version directory is occupied.
File removedFile = new File(file.getAbsoluteFile().getParentFile(), file.getName() + "_removed");
if (!file.renameTo(removedFile))
return false;
// remove json files first to ensure HMCL will not recognize this folder as a valid version.
List<File> jsons = FileUtils.listFilesByExtension(removedFile, "json");
jsons.forEach(f -> {
if (!f.delete())
Logging.LOG.warning("Unable to delete file " + f);
});
versions.remove(id);
return FileUtils.deleteDirectoryQuietly(file);
// remove the version from version list regardless of whether the directory was removed successfully or not.
try {
FileUtils.deleteDirectory(removedFile);
} catch (IOException e) {
Logging.LOG.log(Level.WARNING, "Unable to remove version folder: " + file, e);
}
return true;
}
protected void refreshVersionsImpl() {