Skip to content
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: fix symlink pointing error in filesystem.insertLink #301

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ class Filesystem {
}

insertLink (p) {
const link = path.relative(fs.realpathSync(this.src), fs.realpathSync(p))
const symlink = fs.readlinkSync(p)
const parentPath = path.dirname(p)
const link = path.relative(fs.realpathSync(this.src), path.join(parentPath, symlink))
if (link.substr(0, 2) === '..') {
throw new Error(`${p}: file "${link}" links out of the package`)
}
Expand Down
5 changes: 5 additions & 0 deletions test/api-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,11 @@ describe('api', function () {
asar.extractAll('test/input/extractthis-unpack-dir.asar', 'tmp/extractthis-unpack-dir-api/')
return compDirs('tmp/extractthis-unpack-dir-api/', 'test/expected/extractthis')
})
it('should extract an archive with symlink', async () => {
await asar.createPackageWithOptions('test/input/packthis-with-symlink/', 'tmp/packthis-with-symlink.asar', { dot: false })
asar.extractAll('tmp/packthis-with-symlink.asar', 'tmp/packthis-with-symlink/')
return compFiles('tmp/packthis-with-symlink/real.txt', 'test/input/packthis-with-symlink/real.txt')
})
it('should handle multibyte characters in paths', async () => {
await asar.createPackageWithOptions('test/input/packthis-unicode-path/', 'tmp/packthis-unicode-path.asar', {
globOptions: {
Expand Down
1 change: 1 addition & 0 deletions test/input/packthis-with-symlink/A/real.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
I AM REAL TXT FILE
1 change: 1 addition & 0 deletions test/input/packthis-with-symlink/Current
1 change: 1 addition & 0 deletions test/input/packthis-with-symlink/real.txt
17 changes: 15 additions & 2 deletions test/util/compareFiles.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ module.exports = async function (actualFilePath, expectedFilePath) {
if (process.env.ELECTRON_ASAR_SPEC_UPDATE) {
await fs.writeFile(expectedFilePath, await fs.readFile(actualFilePath))
}
const [actual, expected] = await Promise.all([fs.readFile(actualFilePath, 'utf8'), fs.readFile(expectedFilePath, 'utf8')])
assert.strictEqual(actual, expected)
const [actualFileContent, expectedFileContent] = await Promise.all([fs.readFile(actualFilePath, 'utf8'), fs.readFile(expectedFilePath, 'utf8')])
assert.strictEqual(actualFileContent, expectedFileContent)

const [actualIsSymlink, expectedIsSymlink] = [isSymbolicLinkSync(actualFilePath), isSymbolicLinkSync(expectedFilePath)]
assert.strictEqual(actualIsSymlink, expectedIsSymlink)

if (actualIsSymlink && expectedIsSymlink) {
const [actualSymlinkPointer, expectedSymlinkPointer] = [fs.readlinkSync(actualFilePath), fs.readlinkSync(expectedFilePath)]
assert.strictEqual(actualSymlinkPointer, expectedSymlinkPointer)
}
}

function isSymbolicLinkSync (path) {
const stats = fs.lstatSync(path)
return stats.isSymbolicLink()
}
Loading