From a53041856d8a719efc0ffb257b5ac41961a73554 Mon Sep 17 00:00:00 2001 From: COLAMAroro Date: Tue, 16 May 2023 11:19:47 +0200 Subject: [PATCH] pulsar: 1.104.0 -> 1.105.0 Release note: https://github.com/pulsar-edit/pulsar/releases/tag/v1.105.0 This Pulsar release was made from a Windows computer, the SHA256SUMS.txt file was encoded in UTF-16LE with BOM. Most of the work was enhancing the update script to handle this case. Also implemented the recommendation from SuperSandro2000: https://github.com/NixOS/nixpkgs/pull/226616#discussion_r1170658908 --- pkgs/applications/editors/pulsar/default.nix | 8 +++---- pkgs/applications/editors/pulsar/update.mjs | 25 +++++++++++++++++--- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/pkgs/applications/editors/pulsar/default.nix b/pkgs/applications/editors/pulsar/default.nix index 85b28061e45..a26484c8086 100644 --- a/pkgs/applications/editors/pulsar/default.nix +++ b/pkgs/applications/editors/pulsar/default.nix @@ -23,13 +23,13 @@ let pname = "pulsar"; - version = "1.104.0"; + version = "1.105.0"; sourcesPath = { x86_64-linux.tarname = "Linux.${pname}-${version}.tar.gz"; - x86_64-linux.hash = "sha256-HEMUQVNPb6qWIXX25N79HwHo7j11MyFiBRsq9otdAL8="; + x86_64-linux.hash = "sha256-j2d83m8B6lt1eRAwOOTEq4o+CNe8I+6rkz9qyux55Qw="; aarch64-linux.tarname = "ARM.Linux.${pname}-${version}-arm64.tar.gz"; - aarch64-linux.hash = "sha256-f+s54XtLLdhTFY9caKTKngJF6zLai0F7ur9v37bwuNE="; + aarch64-linux.hash = "sha256-iZVE1R30Tynyn/cAwNIiGrsCMTkWKFUforOkGXSzMsw="; }.${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}"); additionalLibs = lib.makeLibraryPath [ @@ -119,7 +119,7 @@ stdenv.mkDerivation rec { # But asar complains because the node_gyp unpacked dependency uses a prebuilt Python3 itself rm $opt/resources/app.asar.unpacked/node_modules/tree-sitter-bash/build/node_gyp_bins/python3 - ln -s ${python3}/bin/python3 $opt/resources/app.asar.unpacked/node_modules/tree-sitter-bash/build/node_gyp_bins/python3 + ln -s ${python3.interpreter} $opt/resources/app.asar.unpacked/node_modules/tree-sitter-bash/build/node_gyp_bins/python3 '' + '' # Patch the bundled node executables find $opt -name "*.node" -exec patchelf --set-rpath "${newLibpath}:$opt" {} \; diff --git a/pkgs/applications/editors/pulsar/update.mjs b/pkgs/applications/editors/pulsar/update.mjs index 2e4155d8742..4f3d2993e97 100755 --- a/pkgs/applications/editors/pulsar/update.mjs +++ b/pkgs/applications/editors/pulsar/update.mjs @@ -13,6 +13,17 @@ const constants = { targetFile: new URL("default.nix", import.meta.url).pathname, }; +async function utf16ToUtf8(blob) { + // Sometime, upstream saves the SHA256SUMS.txt file in UTF-16, which absolutely breaks node's string handling + // So we need to convert this blob to UTF-8 + + // We need to skip the first 2 bytes, which are the BOM + const arrayBuffer = await blob.slice(2).arrayBuffer(); + const buffer = Buffer.from(arrayBuffer); + const utf8String = buffer.toString('utf16le'); + return utf8String; +} + async function getLatestVersion() { const requestResult = await fetch(constants.githubUrl); if (!requestResult.ok) { @@ -37,6 +48,7 @@ async function getSha256Sum(hashFileContent, targetFile) { let sha256 = hashFileContent. split('\n'). + map(line => line.replace("\r", "")). // Side-effect of the UTF-16 conversion, if the file was created from Windows filter((line) => line.endsWith(targetFile))[0]. split(' ')[0]; @@ -47,14 +59,21 @@ async function getSha256Sums(newVersion) { // Upstream provides a file with the hashes of the files, but it's not in the SRI format, and it refers to the compressed tarball // So let's just use nix-prefetch-url to get the hashes of the decompressed tarball, and `nix hash to-sri` to convert them to SRI format const hashFileUrl = constants.sha256FileURL(newVersion); - const hashFileContent = await fetch(hashFileUrl).then((response) => response.text()); + const hashFileContent = await fetch(hashFileUrl).then((response) => response.blob()); + const headerbuffer = await hashFileContent.slice(0, 2).arrayBuffer() + const header = Buffer.from(headerbuffer).toString('hex'); + + // We must detect if it's UTF-16 or UTF-8. If it's UTF-16, we must convert it to UTF-8, otherwise just use it as-is + const hashFileContentString = header == 'fffe' ? + await utf16ToUtf8(hashFileContent) : + await hashFileContent.text(); let x86_64; let aarch64; console.log("Getting new hashes"); let promises = [ - getSha256Sum(hashFileContent, constants.x86_64FileName(newVersion)).then((hash) => { x86_64 = hash; }), - getSha256Sum(hashFileContent, constants.aarch64FileName(newVersion)).then((hash) => { aarch64 = hash; }), + getSha256Sum(hashFileContentString, constants.x86_64FileName(newVersion)).then((hash) => { x86_64 = hash; }), + getSha256Sum(hashFileContentString, constants.aarch64FileName(newVersion)).then((hash) => { aarch64 = hash; }), ]; await Promise.all(promises); return { x86_64, aarch64 };