From 4627c0670957ee5c5e8506750f4626493aabdc25 Mon Sep 17 00:00:00 2001 From: Darcy Clarke Date: Tue, 27 Jul 2021 11:03:33 -0400 Subject: [PATCH] tar@4.4.15 --- node_modules/tar/lib/strip-absolute-path.js | 14 +++++++++ node_modules/tar/lib/unpack.js | 32 ++++++++++++++++++--- node_modules/tar/lib/write-entry.js | 29 ++++++++++--------- node_modules/tar/package.json | 25 +++++++++------- package-lock.json | 6 ++-- package.json | 2 +- 6 files changed, 76 insertions(+), 32 deletions(-) create mode 100644 node_modules/tar/lib/strip-absolute-path.js diff --git a/node_modules/tar/lib/strip-absolute-path.js b/node_modules/tar/lib/strip-absolute-path.js new file mode 100644 index 0000000000000..49161ddc30473 --- /dev/null +++ b/node_modules/tar/lib/strip-absolute-path.js @@ -0,0 +1,14 @@ +// unix absolute paths are also absolute on win32, so we use this for both +const { isAbsolute, parse } = require('path').win32 + +// returns [root, stripped] +module.exports = path => { + let r = '' + while (isAbsolute(path)) { + // windows will think that //x/y/z has a "root" of //x/y/ + const root = path.charAt(0) === '/' ? '/' : parse(path).root + path = path.substr(root.length) + r += root + } + return [r, path] +} diff --git a/node_modules/tar/lib/unpack.js b/node_modules/tar/lib/unpack.js index fc765096efd11..3a29a65142e3e 100644 --- a/node_modules/tar/lib/unpack.js +++ b/node_modules/tar/lib/unpack.js @@ -9,6 +9,7 @@ const path = require('path') const mkdir = require('./mkdir.js') const mkdirSync = mkdir.sync const wc = require('./winchars.js') +const stripAbsolutePath = require('./strip-absolute-path.js') const ONENTRY = Symbol('onEntry') const CHECKFS = Symbol('checkFs') @@ -195,10 +196,10 @@ class Unpack extends Parser { // absolutes on posix are also absolutes on win32 // so we only need to test this one to get both - if (path.win32.isAbsolute(p)) { - const parsed = path.win32.parse(p) - this.warn('stripping ' + parsed.root + ' from absolute path', p) - entry.path = p.substr(parsed.root.length) + const s = stripAbsolutePath(p) + if (s[0]) { + entry.path = s[1] + this.warn(`stripping ${s[0]} from absolute path`, p) } } @@ -413,6 +414,20 @@ class Unpack extends Parser { // check if a thing is there, and if so, try to clobber it [CHECKFS] (entry) { this[PEND]() + + // if we are not creating a directory, and the path is in the dirCache, + // then that means we are about to delete the directory we created + // previously, and it is no longer going to be a directory, and neither + // is any of its children. + if (entry.type !== 'Directory') { + for (const path of this.dirCache.keys()) { + if (path === entry.absolute || + path.indexOf(entry.absolute + '/') === 0 || + path.indexOf(entry.absolute + '\\') === 0) + this.dirCache.delete(path) + } + } + this[MKDIR](path.dirname(entry.absolute), this.dmode, er => { if (er) return this[ONERROR](er, entry) @@ -474,6 +489,15 @@ class UnpackSync extends Unpack { } [CHECKFS] (entry) { + if (entry.type !== 'Directory') { + for (const path of this.dirCache.keys()) { + if (path === entry.absolute || + path.indexOf(entry.absolute + '/') === 0 || + path.indexOf(entry.absolute + '\\') === 0) + this.dirCache.delete(path) + } + } + const er = this[MKDIR](path.dirname(entry.absolute), this.dmode) if (er) return this[ONERROR](er, entry) diff --git a/node_modules/tar/lib/write-entry.js b/node_modules/tar/lib/write-entry.js index 0c019006f3b67..d7c347f8f62bb 100644 --- a/node_modules/tar/lib/write-entry.js +++ b/node_modules/tar/lib/write-entry.js @@ -26,6 +26,7 @@ const CLOSE = Symbol('close') const MODE = Symbol('mode') const warner = require('./warn-mixin.js') const winchars = require('./winchars.js') +const stripAbsolutePath = require('./strip-absolute-path.js') const modeFix = require('./mode-fix.js') @@ -54,12 +55,12 @@ const WriteEntry = warner(class WriteEntry extends MiniPass { if (typeof opt.onwarn === 'function') this.on('warn', opt.onwarn) - if (!this.preservePaths && path.win32.isAbsolute(p)) { - // absolutes on posix are also absolutes on win32 - // so we only need to test this one to get both - const parsed = path.win32.parse(p) - this.warn('stripping ' + parsed.root + ' from absolute path', p) - this.path = p.substr(parsed.root.length) + if (!this.preservePaths) { + const s = stripAbsolutePath(this.path) + if (s[0]) { + this.path = s[1] + this.warn('stripping ' + s[0] + ' from absolute path', p) + } } this.win32 = !!opt.win32 || process.platform === 'win32' @@ -343,13 +344,15 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass { if (typeof opt.onwarn === 'function') this.on('warn', opt.onwarn) - if (path.isAbsolute(this.path) && !this.preservePaths) { - const parsed = path.parse(this.path) - this.warn( - 'stripping ' + parsed.root + ' from absolute path', - this.path - ) - this.path = this.path.substr(parsed.root.length) + if (!this.preservePaths) { + const s = stripAbsolutePath(this.path) + if (s[0]) { + this.warn( + 'stripping ' + s[0] + ' from absolute path', + this.path + ) + this.path = s[1] + } } this.remain = readEntry.size diff --git a/node_modules/tar/package.json b/node_modules/tar/package.json index b12db0f3ef5ec..89c00d0035345 100644 --- a/node_modules/tar/package.json +++ b/node_modules/tar/package.json @@ -1,8 +1,8 @@ { - "_from": "tar@4.4.13", - "_id": "tar@4.4.13", + "_from": "tar@4.4.15", + "_id": "tar@4.4.15", "_inBundle": false, - "_integrity": "sha512-w2VwSrBoHa5BsSyH+KxEqeQBAllHhccyMFVHtGtdMpF4W7IRWfZjFiQceJPChOeTsSDVUpER2T8FA93pr0L+QA==", + "_integrity": "sha512-ItbufpujXkry7bHH9NpQyTXPbJ72iTlXgkBAYsAjDXk3Ds8t/3NfO5P4xZGy7u+sYuQUbimgzswX4uQIEeNVOA==", "_location": "/tar", "_phantomChildren": { "safe-buffer": "5.1.2", @@ -11,12 +11,12 @@ "_requested": { "type": "version", "registry": true, - "raw": "tar@4.4.13", + "raw": "tar@4.4.15", "name": "tar", "escapedName": "tar", - "rawSpec": "4.4.13", + "rawSpec": "4.4.15", "saveSpec": null, - "fetchSpec": "4.4.13" + "fetchSpec": "4.4.15" }, "_requiredBy": [ "#USER", @@ -24,10 +24,10 @@ "/node-gyp", "/pacote" ], - "_resolved": "https://registry.npmjs.org/tar/-/tar-4.4.13.tgz", - "_shasum": "43b364bc52888d555298637b10d60790254ab525", - "_spec": "tar@4.4.13", - "_where": "/Users/mperrotte/npminc/cli", + "_resolved": "https://registry.npmjs.org/tar/-/tar-4.4.15.tgz", + "_shasum": "3caced4f39ebd46ddda4d6203d48493a919697f8", + "_spec": "tar@4.4.15", + "_where": "/Users/darcyclarke/Documents/Repos/npm/npm6", "author": { "name": "Isaac Z. Schlueter", "email": "i@izs.me", @@ -68,6 +68,9 @@ "homepage": "https://github.com/npm/node-tar#readme", "license": "ISC", "name": "tar", + "publishConfig": { + "tag": "v4-legacy" + }, "repository": { "type": "git", "url": "git+https://github.com/npm/node-tar.git" @@ -84,5 +87,5 @@ "coverage-map": "map.js", "check-coverage": true }, - "version": "4.4.13" + "version": "4.4.15" } diff --git a/package-lock.json b/package-lock.json index 5d005d4be7f80..18a5d9cdaacde 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5552,9 +5552,9 @@ } }, "tar": { - "version": "4.4.13", - "resolved": "https://registry.npmjs.org/tar/-/tar-4.4.13.tgz", - "integrity": "sha512-w2VwSrBoHa5BsSyH+KxEqeQBAllHhccyMFVHtGtdMpF4W7IRWfZjFiQceJPChOeTsSDVUpER2T8FA93pr0L+QA==", + "version": "4.4.15", + "resolved": "https://registry.npmjs.org/tar/-/tar-4.4.15.tgz", + "integrity": "sha512-ItbufpujXkry7bHH9NpQyTXPbJ72iTlXgkBAYsAjDXk3Ds8t/3NfO5P4xZGy7u+sYuQUbimgzswX4uQIEeNVOA==", "requires": { "chownr": "^1.1.1", "fs-minipass": "^1.2.5", diff --git a/package.json b/package.json index 138dce95204f8..5236bb1c5004e 100644 --- a/package.json +++ b/package.json @@ -134,7 +134,7 @@ "sorted-union-stream": "~2.1.3", "ssri": "^6.0.2", "stringify-package": "^1.0.1", - "tar": "^4.4.13", + "tar": "^4.4.15", "text-table": "~0.2.0", "tiny-relative-date": "^1.3.0", "uid-number": "0.0.6",