diff options
Diffstat (limited to 'deps/npm/node_modules/tar/lib/path-reservations.js')
-rw-r--r-- | deps/npm/node_modules/tar/lib/path-reservations.js | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/deps/npm/node_modules/tar/lib/path-reservations.js b/deps/npm/node_modules/tar/lib/path-reservations.js index c0a16b0a1f9..8d0ead9b601 100644 --- a/deps/npm/node_modules/tar/lib/path-reservations.js +++ b/deps/npm/node_modules/tar/lib/path-reservations.js @@ -7,6 +7,12 @@ // while still allowing maximal safe parallelization. const assert = require('assert') +const normPath = require('./normalize-windows-path.js') +const stripSlashes = require('./strip-trailing-slashes.js') +const { join } = require('path') + +const platform = process.env.TESTING_TAR_FAKE_PLATFORM || process.platform +const isWindows = platform === 'win32' module.exports = () => { // path => [function or Set] @@ -18,10 +24,16 @@ module.exports = () => { const reservations = new Map() // return a set of parent dirs for a given path - const { join } = require('path') - const getDirs = path => - join(path).split(/[\\/]/).slice(0, -1).reduce((set, path) => - set.length ? set.concat(join(set[set.length - 1], path)) : [path], []) + // '/a/b/c/d' -> ['/', '/a', '/a/b', '/a/b/c', '/a/b/c/d'] + const getDirs = path => { + const dirs = path.split('/').slice(0, -1).reduce((set, path) => { + if (set.length) + path = normPath(join(set[set.length - 1], path)) + set.push(path || '/') + return set + }, []) + return dirs + } // functions currently running const running = new Set() @@ -97,6 +109,18 @@ module.exports = () => { } const reserve = (paths, fn) => { + // collide on matches across case and unicode normalization + // On windows, thanks to the magic of 8.3 shortnames, it is fundamentally + // impossible to determine whether two paths refer to the same thing on + // disk, without asking the kernel for a shortname. + // So, we just pretend that every path matches every other path here, + // effectively removing all parallelization on windows. + paths = isWindows ? ['win32 parallelization disabled'] : paths.map(p => { + return stripSlashes(normPath(join(p))) + .normalize('NFKD') + .toLowerCase() + }) + const dirs = new Set( paths.map(path => getDirs(path)).reduce((a, b) => a.concat(b)) ) |