fix: breaking versions that inherit from a version being renamed

This commit is contained in:
huanghongxun
2020-04-23 12:28:11 +08:00
parent 9bda50f66e
commit bc842437fa
7 changed files with 16 additions and 8 deletions

View File

@@ -60,7 +60,7 @@ public class DefaultGameBuilder extends GameBuilder {
stages.add(String.format("hmcl.install.%s:%s", remoteVersion.getLibraryId(), remoteVersion.getSelfVersion()));
}
return libraryTask.thenComposeAsync(dependencyManager.getGameRepository()::save).whenComplete(exception -> {
return libraryTask.thenComposeAsync(dependencyManager.getGameRepository()::saveAsync).whenComplete(exception -> {
if (exception != null)
dependencyManager.getGameRepository().removeVersionFromDisk(name);
}).withStagesHint(stages);

View File

@@ -77,7 +77,7 @@ public class GameInstallTask extends Task<Version> {
).withStage("hmcl.install.assets").withRunAsync(() -> {
// ignore failure
})
).thenComposeAsync(gameRepository.save(version)));
).thenComposeAsync(gameRepository.saveAsync(version)));
}
}

View File

@@ -180,6 +180,14 @@ public class DefaultGameRepository implements GameRepository {
if (fromVersion.getId().equals(fromVersion.getJar()))
fromVersion = fromVersion.setJar(null);
FileUtils.writeText(toJson.toFile(), JsonUtils.GSON.toJson(fromVersion.setId(to)));
// fix inheritsFrom of versions that inherits from version [from].
for (Version version : getVersions()) {
if (from.equals(version.getInheritsFrom())) {
File json = getVersionJson(version.getId()).getAbsoluteFile();
FileUtils.writeText(json, JsonUtils.GSON.toJson(version.setInheritsFrom(to)));
}
}
return true;
} catch (IOException | JsonParseException | VersionNotFoundException | InvalidPathException e) {
LOG.log(Level.WARNING, "Unable to rename version " + from + " to " + to, e);
@@ -408,7 +416,7 @@ public class DefaultGameRepository implements GameRepository {
return assetsDir;
}
public Task<Version> save(Version version) {
public Task<Version> saveAsync(Version version) {
if (version.isResolvedPreservingPatches()) {
return new VersionJsonSaveTask(this, MaintainTask.maintainPreservingPatches(this, version));
} else {

View File

@@ -180,7 +180,7 @@ public final class MultiMCModpackInstallTask extends Task<Void> {
FileUtils.copyDirectory(jarmods, repository.getVersionRoot(name).toPath().resolve("jarmods"));
}
dependencies.add(repository.save(version));
dependencies.add(repository.saveAsync(version));
}
@Override