From 331d8d1bb67b3f569a11caf220fb830654a74693 Mon Sep 17 00:00:00 2001 From: huanghongxun Date: Sat, 31 Jul 2021 02:02:06 +0800 Subject: [PATCH] fix: does not remove the old library when updating the library --- .../hmcl/download/DefaultDependencyManager.java | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/DefaultDependencyManager.java b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/DefaultDependencyManager.java index 07dbf9dc1..2a19dee13 100644 --- a/HMCLCore/src/main/java/org/jackhuang/hmcl/download/DefaultDependencyManager.java +++ b/HMCLCore/src/main/java/org/jackhuang/hmcl/download/DefaultDependencyManager.java @@ -33,6 +33,7 @@ import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.Optional; +import java.util.concurrent.atomic.AtomicReference; import static org.jackhuang.hmcl.download.LibraryAnalyzer.LibraryType.OPTIFINE; @@ -130,9 +131,14 @@ public class DefaultDependencyManager extends AbstractDependencyManager { public Task installLibraryAsync(Version baseVersion, RemoteVersion libraryVersion) { if (baseVersion.isResolved()) throw new IllegalArgumentException("Version should not be resolved"); + AtomicReference removedLibraryVersion = new AtomicReference<>(); + return removeLibraryAsync(baseVersion.resolvePreservingPatches(repository), libraryVersion.getLibraryId()) - .thenComposeAsync(version -> libraryVersion.getInstallTask(this, version)) - .thenApplyAsync(baseVersion::addPatch) + .thenComposeAsync(version -> { + removedLibraryVersion.set(version); + return libraryVersion.getInstallTask(this, version); + }) + .thenApplyAsync(patch -> removedLibraryVersion.get().addPatch(patch)) .withStage(String.format("hmcl.install.%s:%s", libraryVersion.getLibraryId(), libraryVersion.getSelfVersion())); }