-
Notifications
You must be signed in to change notification settings - Fork 250
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
fix: Enable getNode
to follow directory links (fixes #248)
#318
Conversation
Follow-up question, why is the getFile (p, followLinks) {
followLinks = typeof followLinks === 'undefined' ? true : followLinks and not getFile (p, followLinks = true) { ? |
getNode
to follow directory links (fixes #248)getNode
to follow directory links (fixes #248)
Should probably land after #320 |
d114c2a
to
0b22b1d
Compare
Rebased. |
Any further input on this? |
test/api-spec.js
Outdated
@@ -168,4 +168,8 @@ describe('api', function () { | |||
|
|||
assert.deepStrictEqual(topLevelFunctions, defaultExportFunctions); | |||
}); | |||
it('should stat a symlinked file', async () => { | |||
const stats = asar.statFile('test/input/stat-symlink.asar', 'real.txt', true); | |||
return assert.strictEqual(stats.size, 19); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we assert that this is not a link instead of checking the size? I think it makes the intent clearer:
return assert.strictEqual(stats.size, 19); | |
return assert.strictEqual(stats.link, undefined); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point. Done.
This demonstrates issue electron#248
When called from stat, getNode should follow directory links to ensure that the correct node is returned. Otherwise, node.files[name] will be undefined, causing a TypeError.
0b22b1d
to
a05f9b6
Compare
🎉 This PR is included in version 3.2.16 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Fixes #248
As reported in the issue, soft links (or symlinks/symbolic links) can cause a
TypeError
to occur inasar.stat
. This happens when a directory below the stat'ed path is actually a link.This commit adds a test demonstrating the problem and fixes the problem by introducing a
followLinks
variable ingetNode
and resolving directory links, if it is set.This is my first PR in this project so any feedback is welcome. I was not sure whether to implement the fix imperatively or recursively, for example. I.e., it is possible to follow the link like this instead: