Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Store version of current bin after downloading. #42

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
/package-lock.json
/index.js
/index.d.ts
/matrix-sdk-crypto.*.node
/matrix-sdk-crypto.*.node*
/docs/*
/target
*.tgz
42 changes: 29 additions & 13 deletions download-lib.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
const { statSync, writeFileSync, readFileSync } = require('fs');
const path = require('path');
const { HttpsProxyAgent } = require("https-proxy-agent");
const { DownloaderHelper } = require("node-downloader-helper");
const { version } = require("./package.json");
Expand All @@ -19,7 +21,24 @@ const byteHelper = function (value) {
return (value / Math.pow(1024, Math.floor(number))).toFixed(1) + " " + units[number];
};

function download_lib(libname) {
async function download_lib(libname) {
const VERSION_FILE = path.join(__dirname, libname + ".version");
try {
statSync(path.join(__dirname, libname));
const downloadedVersion = readFileSync(VERSION_FILE, 'utf-8');
if (downloadedVersion === version) {
console.debug("File already in place, not downloading");
}
return;
} catch (ex) {
if (ex.code === 'ENOENT') {
// Missing file, continue;
} else {
console.error(ex);
process.exit(1);
}
}

let startTime = new Date();

const url = `${DOWNLOADS_BASE_URL}/${CURRENT_VERSION}/${libname}`;
Expand Down Expand Up @@ -52,21 +71,18 @@ function download_lib(libname) {
console.info(`${speed}/s - ${progress}% [${downloaded}/${total}]`);
}
});
dl.start().catch((err) => console.error(err));
try {
await dl.start();
writeFileSync(path.join(__dirname, libname + ".version"), version);
} catch (ex) {
console.error(err);
process.exit(1);
}
}

function isMusl() {
// For Node 10
if (!process.report || typeof process.report.getReport !== "function") {
try {
return readFileSync("/usr/bin/ldd", "utf8").includes("musl");
} catch (e) {
return true;
}
} else {
const { glibcVersionRuntime } = process.report.getReport().header;
return !glibcVersionRuntime;
}
const { glibcVersionRuntime } = process.report.getReport().header;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Node 10 is loooooong dead.

return !glibcVersionRuntime;
}

switch (platform) {
Expand Down
Loading