Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Commit df4a147

Browse files
committed
Merge pull request #38 from piranna/master
[fix] Allow to extract `link` files, fixes #37
2 parents 66ef5e3 + 67fa024 commit df4a147

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

index.js

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ exports.pack = function (cwd, opts) {
7676
fmode |= parseInt(222, 8)
7777
}
7878

79-
var onlink = function (filename, header) {
79+
var onsymlink = function (filename, header) {
8080
xfs.readlink(path.join(cwd, filename), function (err, linkname) {
8181
if (err) return pack.destroy(err)
8282
header.linkname = normalize(linkname)
@@ -111,7 +111,7 @@ exports.pack = function (cwd, opts) {
111111
header.size = 0
112112
header.type = 'symlink'
113113
header = map(header) || header
114-
return onlink(filename, header)
114+
return onsymlink(filename, header)
115115
}
116116

117117
// TODO: add fifo etc...
@@ -237,13 +237,20 @@ exports.extract = function (cwd, opts) {
237237
})
238238
}
239239

240-
var onlink = function () {
240+
var onsymlink = function () {
241241
if (win32) return next() // skip symlinks on win for now before it can be tested
242242
xfs.unlink(name, function () {
243243
xfs.symlink(header.linkname, name, stat)
244244
})
245245
}
246246

247+
var onlink = function () {
248+
if (win32) return next() // skip links on win for now before it can be tested
249+
xfs.unlink(name, function () {
250+
xfs.link(path.resolve(cwd, header.linkname), name, stat)
251+
})
252+
}
253+
247254
var onfile = function () {
248255
var ws = xfs.createWriteStream(name)
249256
var rs = mapStream(stream, header)
@@ -265,15 +272,17 @@ exports.extract = function (cwd, opts) {
265272

266273
mkdirp(path.dirname(name), {fs: xfs}, function (err) {
267274
if (err) return next(err)
268-
if (header.type === 'symlink') return onlink()
269275

270-
if (header.type !== 'file') {
271-
if (strict) return next(new Error('unsupported type for ' + name + ' (' + header.type + ')'))
272-
stream.resume()
273-
return next()
276+
switch (header.type) {
277+
case 'file': return onfile()
278+
case 'link': return onlink()
279+
case 'symlink': return onsymlink()
274280
}
275281

276-
onfile()
282+
if (strict) return next(new Error('unsupported type for ' + name + ' (' + header.type + ')'))
283+
284+
stream.resume()
285+
next()
277286
})
278287
})
279288

0 commit comments

Comments
 (0)