about summary refs log tree commit diff
path: root/pkgs/applications/editors/pulsar
diff options
context:
space:
mode:
authorCOLAMAroro <github@rondier.io>2023-05-16 11:19:47 +0200
committerCOLAMAroro <github@rondier.io>2023-05-16 11:19:47 +0200
commita53041856d8a719efc0ffb257b5ac41961a73554 (patch)
treeb3b72bcd7077b539d00ade3a16324a004083a6ce /pkgs/applications/editors/pulsar
parentc8f6370f7daf435d51d137dcbd80c7ebad1f21f2 (diff)
downloadnixlib-a53041856d8a719efc0ffb257b5ac41961a73554.tar
nixlib-a53041856d8a719efc0ffb257b5ac41961a73554.tar.gz
nixlib-a53041856d8a719efc0ffb257b5ac41961a73554.tar.bz2
nixlib-a53041856d8a719efc0ffb257b5ac41961a73554.tar.lz
nixlib-a53041856d8a719efc0ffb257b5ac41961a73554.tar.xz
nixlib-a53041856d8a719efc0ffb257b5ac41961a73554.tar.zst
nixlib-a53041856d8a719efc0ffb257b5ac41961a73554.zip
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
Diffstat (limited to 'pkgs/applications/editors/pulsar')
-rw-r--r--pkgs/applications/editors/pulsar/default.nix8
-rwxr-xr-xpkgs/applications/editors/pulsar/update.mjs25
2 files changed, 26 insertions, 7 deletions
diff --git a/pkgs/applications/editors/pulsar/default.nix b/pkgs/applications/editors/pulsar/default.nix
index 85b28061e45d..a26484c80861 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 2e4155d87422..4f3d2993e973 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 };