Skip to content

Commit

Permalink
Added option absolute/relative symlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
Ivan Petrovic committed Aug 23, 2019
1 parent 677d5eb commit 27dffcc
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 3 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Returns an EventEmitter with two possible events - `error` on an error, and `ext
**Options**
- **path** *String* - Path to extract into (default `.`)
- **follow** *Boolean* - If true, rather than create stored symlinks as symlinks make a shallow copy of the target instead (default `false`)
- **absolute** *Boolean* - If false, all symlinks will be exported the same way they were created, by default aboslut symlinks will be created (default `true`)
- **filter** *Function* - A function that will be called once for each file in the archive. It takes one argument which is an object containing details of the file. Return true for any file that you want to extract, and false otherwise. (default `null`)
- **strip** *Number* - Remove leading folders in the path structure. Equivalent to `--strip-components` for tar.
- **restrict** *Boolean* - If true, will restrict files from being created outside `options.path`. Setting to `false` has significant security [implications](https://snyk.io/research/zip-slip-vulnerability) if you are extracting untrusted data. (default `true`)
Expand Down
3 changes: 2 additions & 1 deletion lib/decompress-zip.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ DecompressZip.prototype.extract = function (options) {
options.path = options.path || process.cwd();
options.filter = options.filter || null;
options.follow = !!options.follow;
options.absolute = options.absolute !== false;
options.strip = +options.strip || 0;
options.restrict = options.restrict !== false;

Expand Down Expand Up @@ -313,7 +314,7 @@ DecompressZip.prototype.extractFile = function (file, options) {
if (options.follow) {
return extractors.copy(file, destination, this, options.path);
} else {
return extractors.symlink(file, destination, this, options.path);
return extractors.symlink(file, destination, this, options.path, options.absolute);
}
}

Expand Down
4 changes: 2 additions & 2 deletions lib/extractors.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,14 @@ var extractors = {
return {deflated: file.path};
});
},
symlink: function (file, destination, zip, basePath) {
symlink: function (file, destination, zip, basePath, absolute) {
var parent = path.dirname(destination);
return mkdir(parent, zip.dirCache)
.then(function () {
return getLinkLocation(file, destination, zip, basePath);
})
.then(function (linkTo) {
return symlink(path.resolve(parent, linkTo), destination)
return symlink(absolute? path.resolve(parent, linkTo) : linkTo, destination)
.then(function () {
return {symlink: file.path, linkTo: linkTo};
});
Expand Down

0 comments on commit 27dffcc

Please sign in to comment.