Skip to content

Commit 9573cb6

Browse files
abetomoDeviaVir
authored andcommitted
Fix symlink at zip (#348)
* Upgrade archiver In addition I also did the following. - npm update - yarn upgrade * Fix to handle symlink when zipping * Modify timing to execute stat acquisition * Supports nodejs4 It seems that usage of constants is different depending on version * Fix not to test symlink on Windows
1 parent 98a74aa commit 9573cb6

File tree

5 files changed

+92
-97
lines changed

5 files changed

+92
-97
lines changed

lib/main.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -406,9 +406,7 @@ Lambda.prototype._zip = (program, codeDirectory) => {
406406

407407
const filePath = file.path.replace(path.join(codeDirectory, path.sep), '')
408408
if (file.stats.isSymbolicLink()) {
409-
// # archiver.js
410-
// Implementation supporting symlink has been done,
411-
// but it seems that release has not been done yet
409+
return archive.symlink(filePath, fs.readlinkSync(file.path))
412410
}
413411

414412
archive.append(

package-lock.json

Lines changed: 20 additions & 54 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636
"standard": "^10.0.2"
3737
},
3838
"dependencies": {
39-
"archiver": "^1.3.0",
40-
"aws-sdk": "^2.76.0",
41-
"commander": "^2.10.0",
39+
"archiver": "^2.0.0",
40+
"aws-sdk": "^2.81.0",
41+
"commander": "^2.11.0",
4242
"dotenv": "^0.4.0",
4343
"fs-extra": "^0.30.0",
4444
"minimatch": "^3.0.3",

test/main.js

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -529,21 +529,27 @@ describe('lib/main', function () {
529529
return lambda._fileCopy(program, '.', codeDirectory, true)
530530
}).then(() => {
531531
return lambda._npmInstall(program, codeDirectory)
532+
}).then(() => {
533+
if (process.platform !== 'win32') {
534+
fs.symlinkSync(
535+
path.join(__dirname, '..', 'bin', 'node-lambda'),
536+
path.join(codeDirectory, 'node-lambda-link')
537+
)
538+
}
532539
})
533540
})
534541

535542
it('Compress the file. `index.js` and `bin/node-lambda` are included and the permission is also preserved.', function () {
536543
_timeout({ this: this, sec: 30 }) // give it time to zip
537544

538545
return lambda._zip(program, codeDirectory).then((data) => {
539-
const indexJsStat = fs.lstatSync('index.js')
540-
const binNodeLambdaStat = fs.lstatSync(path.join('bin', 'node-lambda'))
541-
542546
const archive = new Zip(data)
543547
assert.include(archive.files['index.js'].name, 'index.js')
544548
assert.include(archive.files['bin/node-lambda'].name, 'bin/node-lambda')
545549

546550
if (process.platform !== 'win32') {
551+
const indexJsStat = fs.lstatSync('index.js')
552+
const binNodeLambdaStat = fs.lstatSync(path.join('bin', 'node-lambda'))
547553
assert.equal(
548554
archive.files['index.js'].unixPermissions,
549555
indexJsStat.mode
@@ -552,6 +558,14 @@ describe('lib/main', function () {
552558
archive.files['bin/node-lambda'].unixPermissions,
553559
binNodeLambdaStat.mode
554560
)
561+
562+
// isSymbolicLink
563+
assert.include(archive.files['node-lambda-link'].name, 'node-lambda-link')
564+
const fsConstants = process.binding('constants').fs || require('constants')
565+
assert.equal(
566+
archive.files['node-lambda-link'].unixPermissions & fsConstants.S_IFMT,
567+
fsConstants.S_IFLNK
568+
)
555569
}
556570
})
557571
})

0 commit comments

Comments
 (0)