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

No symlinks #75

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
sudo: false
language: node_js
node_js:
- '12'
- '10'
- '8'
- '6'
- '4'
8 changes: 6 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ const extractFile = (input, output, opts) => runPlugins(input, opts).then(files

return makeDir(path.dirname(dest))
.then(() => {
if ((x.type === 'link' || x.type === 'symlink') && opts.symlinks === false) {
return;
}

if (x.type === 'link') {
return fsP.link(x.linkname, dest);
}
Expand Down Expand Up @@ -83,12 +87,12 @@ module.exports = (input, output, opts) => {
output = null;
}

opts = Object.assign({plugins: [
opts = {plugins: [
decompressTar(),
decompressTarbz2(),
decompressTargz(),
decompressUnzip()
]}, opts);
], ...opts};

const read = typeof input === 'string' ? fsP.readFile(input) : Promise.resolve(input);

Expand Down
31 changes: 25 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"url": "github.com/kevva"
},
"engines": {
"node": ">=4"
"node": ">=7.6.0"
},
"scripts": {
"test": "xo && ava"
Expand All @@ -35,15 +35,34 @@
"decompress-targz": "^4.0.0",
"decompress-unzip": "^4.0.1",
"graceful-fs": "^4.1.10",
"make-dir": "^1.0.0",
"pify": "^2.3.0",
"strip-dirs": "^2.0.0"
"make-dir": "^3.0.0",
"pify": "^4.0.1",
"strip-dirs": "^3.0.0"
},
"devDependencies": {
"ava": "*",
"is-jpg": "^1.0.0",
"path-exists": "^3.0.0",
"esm": "^3.2.25",
"is-jpg": "^2.0.0",
"path-exists": "^4.0.0",
"pify": "^2.3.0",
"xo": "*"
},
"ava": {
"require": [
"esm"
]
},
"xo": {
"rules": {
"promise/prefer-await-to-then": "warn"
},
"overrides": [
{
"files": "test.js",
"rules": {
"import/default": "ignore"
}
}
]
}
}
10 changes: 8 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@ test.serial('extract file to directory', async t => {
await fsP.unlink(path.join(__dirname, 'test.jpg'));
});

test('extract symlink', async t => {
test.serial('extract without symlink', async t => {
await m(path.join(__dirname, 'fixtures', 'symlink.tar'), __dirname, {strip: 1, symlinks: false});
t.false(fs.existsSync(path.join(__dirname, 'symlink')));
await fsP.unlink(path.join(__dirname, 'file.txt'));
});

test.serial('extract symlink', async t => {
await m(path.join(__dirname, 'fixtures', 'symlink.tar'), __dirname, {strip: 1});
t.is(await fsP.realpath(path.join(__dirname, 'symlink')), path.join(__dirname, 'file.txt'));
await fsP.unlink(path.join(__dirname, 'symlink'));
Expand Down Expand Up @@ -99,7 +105,7 @@ test.serial('set mtime', async t => {
await fsP.unlink(path.join(__dirname, 'test.jpg'));
});

test('return emptpy array if no plugins are set', async t => {
test('return empty array if no plugins are set', async t => {
const files = await m(path.join(__dirname, 'fixtures', 'file.tar'), {plugins: []});
t.is(files.length, 0);
});