Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,8 +36,10 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
Expand All@@ -52,6 +54,8 @@ public void run() throws IOException, InterruptedException {
AssetIndex index = Utils.loadJson(getIndex(), AssetIndex.class);
List<String> keys = new ArrayList<>(index.objects.keySet());
Collections.sort(keys);
removeDuplicateRemotePaths(keys, index);

File assetsPath = new File(Utils.getMCDir(), "/assets/objects");
ExecutorService executorService = Executors.newFixedThreadPool(8);
CopyOnWriteArrayList<String> failedDownloads = new CopyOnWriteArrayList<>();
Expand DownExpand Up@@ -96,6 +100,13 @@ public void run() throws IOException, InterruptedException {
}
}

// Some keys may reference the same remote file. Remove these duplicates to prevent two threads
// writing to the same file on disk.
private static void removeDuplicateRemotePaths(List<String> keys, AssetIndex index) {
Set<String> seen = new HashSet<>(keys.size());
keys.removeIf(key -> !seen.add(index.objects.get(key).getPath()));
}

private File getIndex() throws IOException {
VersionJson json = Utils.loadJson(getMeta().get().getAsFile(), VersionJson.class);
File target = Utils.getCache(getProject(), "assets", "indexes", json.assetIndex.id + ".json");
Expand Down