electron/asar

Package.json from asar.extractAll is not the expected

ajimenez28 opened this issue · 2 comments

Hi all,

I've been using the asar module to extract the package.json, and validate the version of an app from there. In that way, I can automate the validation of different installers. However, the execution of the extractAll method is not working as expected when the app.asar file changes. During the first try, I'm able to get the correct package.json, then when the installation is replaced by a new one, the package.json from the installation is not extracted correctly.

Code
const filepath = path.join(root, location.path, location.folder, location.asarPath, location.asarFile); console.log("Looking for asar file in: ", filepath); if (fs.existsSync(filepath)){ console.log("Asar file has been found"); asar.extractAll(filepath, 'C:/Users/Vagrant/upgrade-tests/asarPkg/'); const pkgjson = 'C:/Users/Vagrant/upgrade-tests/asarPkg/package.json'; const contents = fs.readFileSync(pkgjson, 'utf8'); const data = JSON.parse(contents); console.log("Installed ADN version: ", data.version); if (version === data.version){ installed = true; } }else{ console.log("Asar file has not been found"); }

Extraction looks to be ok, not errors during the execution, but this is what I got in the package.json

lute-path.js":{"size":918,"offset":"3177964"},"strip-trailing-slashes.js":{"size":577,"offset":"3178882"},"types.js":{"size":1095,"offset":"3179459"},"unpack.js":{"size":24285,"offset":"3180554"},"update.js":{"size":852,"offset":"3204839"},"warn-mixin.js":{"size":309,"offset":"3205691"},"winchars.js":{"size":533,"offset":"3206000"},"write-entry.js":{"size":14938,"offset":

I tried without success:

  • Cleaning the destination folder of the extraction.
  • Creating a copy the original app.asar file to another path, and extract from there.

Asar module in version 3.1.0

Does anyone know if the asar module is creating some cache? or which other way can I try to solve this?
Thanks!

It seems to be the asar.extractAll has some issues woking over different app.asar files, but that are comming from the same path. Like a wrong cache. What I did to solve the situation, was to always extract a different app.asar file, creating a copy in other path and adding a number in the name.

`const filepath = path.join(root, location.path, location.folder, location.asarPath, location.asarFile);
console.log("Looking for asar file in: ", filepath);
if (fs.existsSync(filepath)){
const asarExtraction = 'C:/Users/Vagrant/asarPkg/';
const asarFiles = 'C:/Users/Vagrant/asarFiles/';
fs.copyFileSync(filepath, asarFiles+'app'+asarCount+'.asar');
if (fs.existsSync(asarFiles+'app'+asarCount+'.asar')){
console.log("Asar file has been found in", asarFiles+'app'+asarCount+'.asar');
asar.extractAll(asarFiles+'app'+asarCount+'.asar', asarExtraction);
const pkgjson = asarExtraction+'package.json';
const contents = fs.readFileSync(pkgjson, 'utf8');
console.log('contents process', contents);
const data = JSON.parse(contents);
console.log("Installed ADN version: ", data.version);
if (version === data.version){
installed = true;

            }else{
                console.log('Version installed is different than the expected one');
            }
        }else{
            console.log('The asar files is not copied to the asarFiles folder');
        }
        asarCount++;
    }else{
        console.log("Asar file has not been found");
    }`

Sorry for the codes pasted above, they didn't take the format <>