From 9378a8568ed83ea4c46487d2e7c7d2431c453c08 Mon Sep 17 00:00:00 2001 From: Gino Quetua Date: Mon, 30 Nov 2020 15:34:30 +1100 Subject: [PATCH 1/3] do not create target directory if root directory --- index.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 23384ea..3c09f6e 100644 --- a/index.js +++ b/index.js @@ -53,7 +53,9 @@ class Extractor { const destDir = path.dirname(path.join(this.opts.dir, entry.fileName)) try { - await fs.mkdir(destDir, { recursive: true }) + if (!path.parse(process.cwd()).root === destDir) { + await fs.mkdir(destDir, { recursive: true }) + } const canonicalDestDir = await fs.realpath(destDir) const relativeDestDir = path.relative(this.opts.dir, canonicalDestDir) @@ -167,7 +169,10 @@ module.exports = async function (zipPath, opts) { throw new Error('Target directory is expected to be absolute') } - await fs.mkdir(opts.dir, { recursive: true }) + if (!path.parse(process.cwd()).root === opts.dir) { + await fs.mkdir(opts.dir, { recursive: true }) + } + opts.dir = await fs.realpath(opts.dir) return new Extractor(zipPath, opts).extract() } From e7988ef182a20ea4dd7e142dead162369e7c5e97 Mon Sep 17 00:00:00 2001 From: superigno Date: Mon, 30 Nov 2020 15:48:48 +1100 Subject: [PATCH 2/3] Update index.js Co-authored-by: Pedro Augusto de Paula Barbosa --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 3c09f6e..626885d 100644 --- a/index.js +++ b/index.js @@ -53,7 +53,7 @@ class Extractor { const destDir = path.dirname(path.join(this.opts.dir, entry.fileName)) try { - if (!path.parse(process.cwd()).root === destDir) { + if (path.parse(process.cwd()).root !== destDir) { await fs.mkdir(destDir, { recursive: true }) } From f64884c92dc14b9046be8382f3b6c65779b70ccc Mon Sep 17 00:00:00 2001 From: superigno Date: Mon, 30 Nov 2020 15:49:10 +1100 Subject: [PATCH 3/3] Update index.js Co-authored-by: Pedro Augusto de Paula Barbosa --- index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.js b/index.js index 626885d..ed7b3da 100644 --- a/index.js +++ b/index.js @@ -169,7 +169,7 @@ module.exports = async function (zipPath, opts) { throw new Error('Target directory is expected to be absolute') } - if (!path.parse(process.cwd()).root === opts.dir) { + if (path.parse(process.cwd()).root !== opts.dir) { await fs.mkdir(opts.dir, { recursive: true }) }