asar icon indicating copy to clipboard operation
asar copied to clipboard

fails with an error "No such file or directory"

Open integral-llc opened this issue 9 years ago • 13 comments

when trying to extract all files from an .asar file I'm getting such an error.

asar extract app.asar ./app
fs.js:565
fs.write = function(fd, buffer, offset, length, position, callback) {
                                                 ^
Error: ENOENT, no such file or directory '/Users/maddev/Documents/projects/personal/slack/app.asar.unpacked/node_modules/cld-atom-shell/build/Release/cld.node'
    at Error (native)
    at Object.fs.openSync (fs.js:500:18)
    at Object.fs.readFileSync (fs.js:352:15)
    at Object.module.exports.readFileSync (/opt/local/lib/node_modules/asar/lib/disk.js:121:19)
    at Object.module.exports.extractAll (/opt/local/lib/node_modules/asar/lib/asar.js:115:24)
    at Command.<anonymous> (/opt/local/lib/node_modules/asar/bin/asar:53:15)
    at Command.listener (/opt/local/lib/node_modules/asar/node_modules/commander/index.js:249:8)
    at Command.emit (events.js:110:17)
    at Command.parseArgs (/opt/local/lib/node_modules/asar/node_modules/commander/index.js:480:12)
    at Command.parse (/opt/local/lib/node_modules/asar/node_modules/commander/index.js:372:21)

what is the problem here? thx

integral-llc avatar Jun 05 '15 20:06 integral-llc

Someone?

Lazarencjusz avatar Jul 14 '15 14:07 Lazarencjusz

I've encountered this problem as well. I don't know why this works, but I went into asar/lib/disk.js, inside the method readFileSync(...), and changed the following:

if (info.unpacked) {
    ...
} else { ... }

to:

if (false) {
    ...
} else { ... }

I was then able to unpack the file.

jrop avatar Feb 08 '16 18:02 jrop

+1 it's not working...Error: ENOENT: no such file or directory when trying to extract

gobijan avatar Feb 26 '16 17:02 gobijan

I just ran into this problem myself... I believe it is because the asar has excluded directories from the .asar package and to successfully unpack it you need to have the 'app.asar.unpacked' directory adjacent to the .asar file while extracting.

ashelley avatar Jul 19 '16 16:07 ashelley

Can anyone provide an example .asar file that fails to extract?

kevinsawicki avatar Aug 18 '16 22:08 kevinsawicki

A possible workaround is to use absolute paths for the archive argument. eg asar.extractAll(__dirname + 'src.asar', 'dest')

samCrock avatar May 03 '17 13:05 samCrock

@kevinsawicki The only .asar I know of off the top of my head is the GitKraken app.asar on macOS. I just tried this again, and I get the same error.

  1. Obtain the GitKraken app.asar
  2. Run asar e app.asar gitkraken/

Output:

fs.js:583
  return binding.open(pathModule._makeLong(path), stringToFlags(flags), mode);
                 ^

Error: ENOENT: no such file or directory, open '/home/me/Desktop/gitkraken/app.asar.unpacked/node_modules/@paulcbetts/system-idle-time/build/Release/system_idle_time.node'
    at Object.fs.openSync (fs.js:583:18)
    at Object.fs.readFileSync (fs.js:490:33)
    at Object.module.exports.readFileSync (/home/me/.config/yarn/global/node_modules/asar/lib/disk.js:111:17)
    at filenames.map (/home/me/.config/yarn/global/node_modules/asar/lib/asar.js:214:28)
    at Array.map (native)
    at Object.module.exports.extractAll (/home/me/.config/yarn/global/node_modules/asar/lib/asar.js:192:20)
    at Command.<anonymous> (/home/me/.config/yarn/global/node_modules/asar/bin/asar.js:60:15)
    at Command.listener (/home/me/.config/yarn/global/node_modules/commander/index.js:301:8)
    at emitTwo (events.js:106:13)
    at Command.emit (events.js:194:7)

jrop avatar May 03 '17 16:05 jrop

This issue is pretty straight forward. Basically lots of apps have an app.asar file but they also have an app.asar.unpacked folder for some files that shouldn't live in an ASAR. This means that an ASAR file will not extract correctly unless both the app.asar.unpacked and app.asar files are in the same location.

MarshallOfSound avatar May 03 '17 16:05 MarshallOfSound

@MarshallOfSound Okay, thanks. Learn something new everyday

jrop avatar May 03 '17 16:05 jrop

went into asar/lib/disk.js, inside the method readFileSync(...), and changed the following: if (info.unpacked) { // it's an unpacked file, copy it. buffer = fs.readFileSync(path.join(${filesystem.src}.unpacked, filename)) } else { ...... }

to

if (info.unpacked) { // it's an unpacked file, copy it. //buffer = fs.readFileSync(path.join(${filesystem.src}.unpacked, filename)) } else { ...... }

blovercat avatar Jun 30 '17 09:06 blovercat

as @MarshallOfSound mentioned to unpack the asar archive you would also need a folder app.asar.unpacked in the same directory as your app.asar file. Read more here:

Adding Unpacked Files in asar Archiv

Saw-mon-and-Natalie avatar Oct 16 '17 05:10 Saw-mon-and-Natalie

And if you don't have the app.asar.unpacked folder WITH the ~original files, then the extract process fails and halts, and you can't easily extract the rest of the files. The above source code hack works, but then probably prevents extract working for files that were listed but not actually packed (for people that want that). It would be nice if asar extract had an additional option to ignore asar.unpacked errors, maybe even by default, or at least some help text specifying on that error, that you can specify this extra option to fully extract all the actually packed files.

vulture avatar Feb 15 '18 17:02 vulture

This is the exact problem that I had, I placed the app.asar.unpacked folder in the same place as the app.asar and everything worked like a charm. Maybe a clear message telling you to do this could be added ?

mcirsta avatar Feb 26 '23 19:02 mcirsta