feat: only download natives if not present

This commit is contained in:
HerozDotExe 2026-02-26 19:32:28 +01:00
parent 5c82c9059e
commit 707f0c013f
2 changed files with 13 additions and 6 deletions

View file

@ -18,7 +18,7 @@ async function getNatives(versionManifest: Version, tempNativesPath: string) {
const native: Native =
os() === "osx"
? library.downloads.classifiers["natives-osx"] ||
library.downloads.classifiers["natives-macos"]
library.downloads.classifiers["natives-macos"]
: library.downloads.classifiers[`natives-${os()}`];
const destination = path.join(
@ -48,6 +48,7 @@ export async function NativesDownloader(
nativesPath,
tempNativesPath,
[".git", "META-INF", ".sha1"],
"skip",
{
pQueueOptions: {
concurrency: 5,

View file

@ -2,8 +2,9 @@ import AdmZip from "adm-zip";
import { PoolFile, PoolOptions } from "./types";
import { downloadFile, DownloadPool } from "./fetch";
import path from "path";
import { exists } from "./fs";
export function unzipAll(from: string, to: string, filters: string[]) {
export async function unzipAll(from: string, to: string, filters: string[], mode: "overwrite" | "skip") {
const zip = new AdmZip(from);
for (const entry of zip.getEntries()) {
@ -14,7 +15,9 @@ export function unzipAll(from: string, to: string, filters: string[]) {
}
}
if (shouldSkip) continue;
zip.extractEntryTo(entry.entryName, to);
if (!await exists(path.join(to, entry.entryName)) || mode === "overwrite") {
zip.extractEntryTo(entry.entryName, to);
}
}
}
@ -22,27 +25,30 @@ export class DownloadAndUnzipPool extends DownloadPool {
destination: string;
tempPath: string;
filters: string[];
unzipMode: "overwrite" | "skip"
constructor(
elements: PoolFile[],
destination: string,
tempPath: string,
filters: string[] = [],
unzipMode: "overwrite" | "skip",
options: PoolOptions = { pQueueOptions: {}, overwrite: true },
) {
super(elements, options);
this.tempPath = tempPath;
this.destination = destination;
this.filters = filters;
this.unzipMode = unzipMode
}
async downloadAndUnzip(file: PoolFile, filters: string[]) {
async downloadAndUnzip(file: PoolFile, filters: string[], unzipMode: "overwrite" | "skip") {
const tempFile = path.join(this.tempPath, path.basename(file.path));
await downloadFile({
url: file.url,
path: tempFile,
});
unzipAll(tempFile, this.destination, filters);
unzipAll(tempFile, this.destination, filters, unzipMode);
}
async run() {
@ -50,7 +56,7 @@ export class DownloadAndUnzipPool extends DownloadPool {
this.totalSize += element.size;
this.add(async () => {
await this.downloadAndUnzip(element, this.filters);
await this.downloadAndUnzip(element, this.filters, this.unzipMode);
// update status here to ensure that it is run before "completed" events listeners
this.done++;
this.doneSize += element.size;