tar 4.4.12 → 4.4.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/extract.js +4 -3
- package/lib/list.js +4 -3
- package/lib/mkdir.js +55 -48
- package/lib/normalize-windows-path.js +8 -0
- package/lib/pack.js +8 -18
- package/lib/path-reservations.js +127 -0
- package/lib/read-entry.js +4 -3
- package/lib/replace.js +2 -1
- package/lib/strip-absolute-path.js +14 -0
- package/lib/strip-trailing-slashes.js +24 -0
- package/lib/unpack.js +238 -85
- package/lib/write-entry.js +178 -82
- package/package.json +18 -12
package/lib/extract.js
CHANGED
|
@@ -6,6 +6,7 @@ const Unpack = require('./unpack.js')
|
|
|
6
6
|
const fs = require('fs')
|
|
7
7
|
const fsm = require('fs-minipass')
|
|
8
8
|
const path = require('path')
|
|
9
|
+
const stripSlash = require('./strip-trailing-slashes.js')
|
|
9
10
|
|
|
10
11
|
const x = module.exports = (opt_, files, cb) => {
|
|
11
12
|
if (typeof opt_ === 'function')
|
|
@@ -41,7 +42,7 @@ const x = module.exports = (opt_, files, cb) => {
|
|
|
41
42
|
// construct a filter that limits the file entries listed
|
|
42
43
|
// include child entries if a dir is included
|
|
43
44
|
const filesFilter = (opt, files) => {
|
|
44
|
-
const map = new Map(files.map(f => [f
|
|
45
|
+
const map = new Map(files.map(f => [stripSlash(f), true]))
|
|
45
46
|
const filter = opt.filter
|
|
46
47
|
|
|
47
48
|
const mapHas = (file, r) => {
|
|
@@ -55,8 +56,8 @@ const filesFilter = (opt, files) => {
|
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
opt.filter = filter
|
|
58
|
-
? (file, entry) => filter(file, entry) && mapHas(file
|
|
59
|
-
: file => mapHas(file
|
|
59
|
+
? (file, entry) => filter(file, entry) && mapHas(stripSlash(file))
|
|
60
|
+
: file => mapHas(stripSlash(file))
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
const extractFileSync = opt => {
|
package/lib/list.js
CHANGED
|
@@ -11,6 +11,7 @@ const Parser = require('./parse.js')
|
|
|
11
11
|
const fs = require('fs')
|
|
12
12
|
const fsm = require('fs-minipass')
|
|
13
13
|
const path = require('path')
|
|
14
|
+
const stripSlash = require('./strip-trailing-slashes.js')
|
|
14
15
|
|
|
15
16
|
const t = module.exports = (opt_, files, cb) => {
|
|
16
17
|
if (typeof opt_ === 'function')
|
|
@@ -56,7 +57,7 @@ const onentryFunction = opt => {
|
|
|
56
57
|
// construct a filter that limits the file entries listed
|
|
57
58
|
// include child entries if a dir is included
|
|
58
59
|
const filesFilter = (opt, files) => {
|
|
59
|
-
const map = new Map(files.map(f => [f
|
|
60
|
+
const map = new Map(files.map(f => [stripSlash(f), true]))
|
|
60
61
|
const filter = opt.filter
|
|
61
62
|
|
|
62
63
|
const mapHas = (file, r) => {
|
|
@@ -70,8 +71,8 @@ const filesFilter = (opt, files) => {
|
|
|
70
71
|
}
|
|
71
72
|
|
|
72
73
|
opt.filter = filter
|
|
73
|
-
? (file, entry) => filter(file, entry) && mapHas(file
|
|
74
|
-
: file => mapHas(file
|
|
74
|
+
? (file, entry) => filter(file, entry) && mapHas(stripSlash(file))
|
|
75
|
+
: file => mapHas(stripSlash(file))
|
|
75
76
|
}
|
|
76
77
|
|
|
77
78
|
const listFileSync = opt => {
|
package/lib/mkdir.js
CHANGED
|
@@ -8,6 +8,7 @@ const mkdirp = require('mkdirp')
|
|
|
8
8
|
const fs = require('fs')
|
|
9
9
|
const path = require('path')
|
|
10
10
|
const chownr = require('chownr')
|
|
11
|
+
const normPath = require('./normalize-windows-path.js')
|
|
11
12
|
|
|
12
13
|
class SymlinkError extends Error {
|
|
13
14
|
constructor (symlink, path) {
|
|
@@ -33,7 +34,20 @@ class CwdError extends Error {
|
|
|
33
34
|
}
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
const
|
|
37
|
+
const cGet = (cache, key) => cache.get(normPath(key))
|
|
38
|
+
const cSet = (cache, key, val) => cache.set(normPath(key), val)
|
|
39
|
+
|
|
40
|
+
const checkCwd = (dir, cb) => {
|
|
41
|
+
fs.stat(dir, (er, st) => {
|
|
42
|
+
if (er || !st.isDirectory())
|
|
43
|
+
er = new CwdError(dir, er && er.code || 'ENOTDIR')
|
|
44
|
+
cb(er)
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
module.exports = (dir, opt, cb) => {
|
|
49
|
+
dir = normPath(dir)
|
|
50
|
+
|
|
37
51
|
// if there's any overlap between mask and mode,
|
|
38
52
|
// then we'll need an explicit chmod
|
|
39
53
|
const umask = opt.umask
|
|
@@ -49,13 +63,13 @@ const mkdir = module.exports = (dir, opt, cb) => {
|
|
|
49
63
|
const preserve = opt.preserve
|
|
50
64
|
const unlink = opt.unlink
|
|
51
65
|
const cache = opt.cache
|
|
52
|
-
const cwd = opt.cwd
|
|
66
|
+
const cwd = normPath(opt.cwd)
|
|
53
67
|
|
|
54
68
|
const done = (er, created) => {
|
|
55
69
|
if (er)
|
|
56
70
|
cb(er)
|
|
57
71
|
else {
|
|
58
|
-
cache
|
|
72
|
+
cSet(cache, dir, true)
|
|
59
73
|
if (created && doChown)
|
|
60
74
|
chownr(created, uid, gid, er => done(er))
|
|
61
75
|
else if (needChmod)
|
|
@@ -65,21 +79,17 @@ const mkdir = module.exports = (dir, opt, cb) => {
|
|
|
65
79
|
}
|
|
66
80
|
}
|
|
67
81
|
|
|
68
|
-
if (cache && cache
|
|
82
|
+
if (cache && cGet(cache, dir) === true)
|
|
69
83
|
return done()
|
|
70
84
|
|
|
71
85
|
if (dir === cwd)
|
|
72
|
-
return
|
|
73
|
-
if (er || !st.isDirectory())
|
|
74
|
-
er = new CwdError(dir, er && er.code || 'ENOTDIR')
|
|
75
|
-
done(er)
|
|
76
|
-
})
|
|
86
|
+
return checkCwd(dir, done)
|
|
77
87
|
|
|
78
88
|
if (preserve)
|
|
79
89
|
return mkdirp(dir, mode, done)
|
|
80
90
|
|
|
81
|
-
const sub = path.relative(cwd, dir)
|
|
82
|
-
const parts = sub.split(
|
|
91
|
+
const sub = normPath(path.relative(cwd, dir))
|
|
92
|
+
const parts = sub.split('/')
|
|
83
93
|
mkdir_(cwd, parts, mode, cache, unlink, cwd, null, done)
|
|
84
94
|
}
|
|
85
95
|
|
|
@@ -87,22 +97,19 @@ const mkdir_ = (base, parts, mode, cache, unlink, cwd, created, cb) => {
|
|
|
87
97
|
if (!parts.length)
|
|
88
98
|
return cb(null, created)
|
|
89
99
|
const p = parts.shift()
|
|
90
|
-
const part = base + '/' + p
|
|
91
|
-
if (cache
|
|
100
|
+
const part = normPath(path.resolve(base + '/' + p))
|
|
101
|
+
if (cGet(cache, part))
|
|
92
102
|
return mkdir_(part, parts, mode, cache, unlink, cwd, created, cb)
|
|
93
103
|
fs.mkdir(part, mode, onmkdir(part, parts, mode, cache, unlink, cwd, created, cb))
|
|
94
104
|
}
|
|
95
105
|
|
|
96
106
|
const onmkdir = (part, parts, mode, cache, unlink, cwd, created, cb) => er => {
|
|
97
107
|
if (er) {
|
|
98
|
-
if (er.path && path.dirname(er.path) === cwd &&
|
|
99
|
-
(er.code === 'ENOTDIR' || er.code === 'ENOENT'))
|
|
100
|
-
return cb(new CwdError(cwd, er.code))
|
|
101
|
-
|
|
102
108
|
fs.lstat(part, (statEr, st) => {
|
|
103
|
-
if (statEr)
|
|
109
|
+
if (statEr) {
|
|
110
|
+
statEr.path = statEr.path && normPath(statEr.path)
|
|
104
111
|
cb(statEr)
|
|
105
|
-
else if (st.isDirectory())
|
|
112
|
+
} else if (st.isDirectory())
|
|
106
113
|
mkdir_(part, parts, mode, cache, unlink, cwd, created, cb)
|
|
107
114
|
else if (unlink)
|
|
108
115
|
fs.unlink(part, er => {
|
|
@@ -121,7 +128,21 @@ const onmkdir = (part, parts, mode, cache, unlink, cwd, created, cb) => er => {
|
|
|
121
128
|
}
|
|
122
129
|
}
|
|
123
130
|
|
|
124
|
-
const
|
|
131
|
+
const checkCwdSync = dir => {
|
|
132
|
+
let ok = false
|
|
133
|
+
let code = 'ENOTDIR'
|
|
134
|
+
try {
|
|
135
|
+
ok = fs.statSync(dir).isDirectory()
|
|
136
|
+
} catch (er) {
|
|
137
|
+
code = er.code
|
|
138
|
+
} finally {
|
|
139
|
+
if (!ok)
|
|
140
|
+
throw new CwdError(dir, code)
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
module.exports.sync = (dir, opt) => {
|
|
145
|
+
dir = normPath(dir)
|
|
125
146
|
// if there's any overlap between mask and mode,
|
|
126
147
|
// then we'll need an explicit chmod
|
|
127
148
|
const umask = opt.umask
|
|
@@ -137,65 +158,51 @@ const mkdirSync = module.exports.sync = (dir, opt) => {
|
|
|
137
158
|
const preserve = opt.preserve
|
|
138
159
|
const unlink = opt.unlink
|
|
139
160
|
const cache = opt.cache
|
|
140
|
-
const cwd = opt.cwd
|
|
161
|
+
const cwd = normPath(opt.cwd)
|
|
141
162
|
|
|
142
163
|
const done = (created) => {
|
|
143
|
-
cache
|
|
164
|
+
cSet(cache, dir, true)
|
|
144
165
|
if (created && doChown)
|
|
145
166
|
chownr.sync(created, uid, gid)
|
|
146
167
|
if (needChmod)
|
|
147
168
|
fs.chmodSync(dir, mode)
|
|
148
169
|
}
|
|
149
170
|
|
|
150
|
-
if (cache && cache
|
|
171
|
+
if (cache && cGet(cache, dir) === true)
|
|
151
172
|
return done()
|
|
152
173
|
|
|
153
174
|
if (dir === cwd) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
try {
|
|
157
|
-
ok = fs.statSync(dir).isDirectory()
|
|
158
|
-
} catch (er) {
|
|
159
|
-
code = er.code
|
|
160
|
-
} finally {
|
|
161
|
-
if (!ok)
|
|
162
|
-
throw new CwdError(dir, code)
|
|
163
|
-
}
|
|
164
|
-
done()
|
|
165
|
-
return
|
|
175
|
+
checkCwdSync(cwd)
|
|
176
|
+
return done()
|
|
166
177
|
}
|
|
167
178
|
|
|
168
179
|
if (preserve)
|
|
169
180
|
return done(mkdirp.sync(dir, mode))
|
|
170
181
|
|
|
171
|
-
const sub = path.relative(cwd, dir)
|
|
172
|
-
const parts = sub.split(
|
|
182
|
+
const sub = normPath(path.relative(cwd, dir))
|
|
183
|
+
const parts = sub.split('/')
|
|
173
184
|
let created = null
|
|
174
185
|
for (let p = parts.shift(), part = cwd;
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
if (cache
|
|
186
|
+
p && (part += '/' + p);
|
|
187
|
+
p = parts.shift()) {
|
|
188
|
+
part = normPath(path.resolve(part))
|
|
189
|
+
if (cGet(cache, part))
|
|
179
190
|
continue
|
|
180
191
|
|
|
181
192
|
try {
|
|
182
193
|
fs.mkdirSync(part, mode)
|
|
183
194
|
created = created || part
|
|
184
|
-
cache
|
|
195
|
+
cSet(cache, part, true)
|
|
185
196
|
} catch (er) {
|
|
186
|
-
if (er.path && path.dirname(er.path) === cwd &&
|
|
187
|
-
(er.code === 'ENOTDIR' || er.code === 'ENOENT'))
|
|
188
|
-
return new CwdError(cwd, er.code)
|
|
189
|
-
|
|
190
197
|
const st = fs.lstatSync(part)
|
|
191
198
|
if (st.isDirectory()) {
|
|
192
|
-
cache
|
|
199
|
+
cSet(cache, part, true)
|
|
193
200
|
continue
|
|
194
201
|
} else if (unlink) {
|
|
195
202
|
fs.unlinkSync(part)
|
|
196
203
|
fs.mkdirSync(part, mode)
|
|
197
204
|
created = created || part
|
|
198
|
-
cache
|
|
205
|
+
cSet(cache, part, true)
|
|
199
206
|
continue
|
|
200
207
|
} else if (st.isSymbolicLink())
|
|
201
208
|
return new SymlinkError(part, part + '/' + parts.join('/'))
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// on windows, either \ or / are valid directory separators.
|
|
2
|
+
// on unix, \ is a valid character in filenames.
|
|
3
|
+
// so, on windows, and only on windows, we replace all \ chars with /,
|
|
4
|
+
// so that we can use / as our one and only directory separator char.
|
|
5
|
+
|
|
6
|
+
const platform = process.env.TESTING_TAR_FAKE_PLATFORM || process.platform
|
|
7
|
+
module.exports = platform !== 'win32' ? p => p
|
|
8
|
+
: p => p && p.replace(/\\/g, '/')
|
package/lib/pack.js
CHANGED
|
@@ -56,6 +56,7 @@ const ONDRAIN = Symbol('ondrain')
|
|
|
56
56
|
const fs = require('fs')
|
|
57
57
|
const path = require('path')
|
|
58
58
|
const warner = require('./warn-mixin.js')
|
|
59
|
+
const normPath = require('./normalize-windows-path.js')
|
|
59
60
|
|
|
60
61
|
const Pack = warner(class Pack extends MiniPass {
|
|
61
62
|
constructor (opt) {
|
|
@@ -67,7 +68,7 @@ const Pack = warner(class Pack extends MiniPass {
|
|
|
67
68
|
this.preservePaths = !!opt.preservePaths
|
|
68
69
|
this.strict = !!opt.strict
|
|
69
70
|
this.noPax = !!opt.noPax
|
|
70
|
-
this.prefix = (opt.prefix || '')
|
|
71
|
+
this.prefix = normPath(opt.prefix || '')
|
|
71
72
|
this.linkCache = opt.linkCache || new Map()
|
|
72
73
|
this.statCache = opt.statCache || new Map()
|
|
73
74
|
this.readdirCache = opt.readdirCache || new Map()
|
|
@@ -132,10 +133,7 @@ const Pack = warner(class Pack extends MiniPass {
|
|
|
132
133
|
}
|
|
133
134
|
|
|
134
135
|
[ADDTARENTRY] (p) {
|
|
135
|
-
const absolute = path.resolve(this.cwd, p.path)
|
|
136
|
-
if (this.prefix)
|
|
137
|
-
p.path = this.prefix + '/' + p.path.replace(/^\.(\/+|$)/, '')
|
|
138
|
-
|
|
136
|
+
const absolute = normPath(path.resolve(this.cwd, p.path))
|
|
139
137
|
// in this case, we don't have to wait for the stat
|
|
140
138
|
if (!this.filter(p.path, p))
|
|
141
139
|
p.resume()
|
|
@@ -151,10 +149,7 @@ const Pack = warner(class Pack extends MiniPass {
|
|
|
151
149
|
}
|
|
152
150
|
|
|
153
151
|
[ADDFSENTRY] (p) {
|
|
154
|
-
const absolute = path.resolve(this.cwd, p)
|
|
155
|
-
if (this.prefix)
|
|
156
|
-
p = this.prefix + '/' + p.replace(/^\.(\/+|$)/, '')
|
|
157
|
-
|
|
152
|
+
const absolute = normPath(path.resolve(this.cwd, p))
|
|
158
153
|
this[QUEUE].push(new PackJob(p, absolute))
|
|
159
154
|
this[PROCESS]()
|
|
160
155
|
}
|
|
@@ -298,7 +293,8 @@ const Pack = warner(class Pack extends MiniPass {
|
|
|
298
293
|
linkCache: this.linkCache,
|
|
299
294
|
statCache: this.statCache,
|
|
300
295
|
noMtime: this.noMtime,
|
|
301
|
-
mtime: this.mtime
|
|
296
|
+
mtime: this.mtime,
|
|
297
|
+
prefix: this.prefix,
|
|
302
298
|
}
|
|
303
299
|
}
|
|
304
300
|
|
|
@@ -324,10 +320,7 @@ const Pack = warner(class Pack extends MiniPass {
|
|
|
324
320
|
|
|
325
321
|
if (job.readdir)
|
|
326
322
|
job.readdir.forEach(entry => {
|
|
327
|
-
const p =
|
|
328
|
-
job.path.slice(this.prefix.length + 1) || './'
|
|
329
|
-
: job.path
|
|
330
|
-
|
|
323
|
+
const p = job.path
|
|
331
324
|
const base = p === './' ? '' : p.replace(/\/*$/, '/')
|
|
332
325
|
this[ADDFSENTRY](base + entry)
|
|
333
326
|
})
|
|
@@ -380,10 +373,7 @@ class PackSync extends Pack {
|
|
|
380
373
|
|
|
381
374
|
if (job.readdir)
|
|
382
375
|
job.readdir.forEach(entry => {
|
|
383
|
-
const p =
|
|
384
|
-
job.path.slice(this.prefix.length + 1) || './'
|
|
385
|
-
: job.path
|
|
386
|
-
|
|
376
|
+
const p = job.path
|
|
387
377
|
const base = p === './' ? '' : p.replace(/\/*$/, '/')
|
|
388
378
|
this[ADDFSENTRY](base + entry)
|
|
389
379
|
})
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// A path exclusive reservation system
|
|
2
|
+
// reserve([list, of, paths], fn)
|
|
3
|
+
// When the fn is first in line for all its paths, it
|
|
4
|
+
// is called with a cb that clears the reservation.
|
|
5
|
+
//
|
|
6
|
+
// Used by async unpack to avoid clobbering paths in use,
|
|
7
|
+
// while still allowing maximal safe parallelization.
|
|
8
|
+
|
|
9
|
+
const assert = require('assert')
|
|
10
|
+
const normPath = require('./normalize-windows-path.js')
|
|
11
|
+
|
|
12
|
+
module.exports = () => {
|
|
13
|
+
// path => [function or Set]
|
|
14
|
+
// A Set object means a directory reservation
|
|
15
|
+
// A fn is a direct reservation on that path
|
|
16
|
+
const queues = new Map()
|
|
17
|
+
|
|
18
|
+
// fn => {paths:[path,...], dirs:[path, ...]}
|
|
19
|
+
const reservations = new Map()
|
|
20
|
+
|
|
21
|
+
// return a set of parent dirs for a given path
|
|
22
|
+
const { join } = require('path')
|
|
23
|
+
const getDirs = path =>
|
|
24
|
+
normPath(join(path)).split('/').slice(0, -1).reduce((set, path) =>
|
|
25
|
+
set.length ? set.concat(normPath(join(set[set.length-1], path)))
|
|
26
|
+
: [path], [])
|
|
27
|
+
|
|
28
|
+
// functions currently running
|
|
29
|
+
const running = new Set()
|
|
30
|
+
|
|
31
|
+
// return the queues for each path the function cares about
|
|
32
|
+
// fn => {paths, dirs}
|
|
33
|
+
const getQueues = fn => {
|
|
34
|
+
const res = reservations.get(fn)
|
|
35
|
+
/* istanbul ignore if - unpossible */
|
|
36
|
+
if (!res)
|
|
37
|
+
throw new Error('function does not have any path reservations')
|
|
38
|
+
return {
|
|
39
|
+
paths: res.paths.map(path => queues.get(path)),
|
|
40
|
+
dirs: [...res.dirs].map(path => queues.get(path)),
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// check if fn is first in line for all its paths, and is
|
|
45
|
+
// included in the first set for all its dir queues
|
|
46
|
+
const check = fn => {
|
|
47
|
+
const {paths, dirs} = getQueues(fn)
|
|
48
|
+
return paths.every(q => q[0] === fn) &&
|
|
49
|
+
dirs.every(q => q[0] instanceof Set && q[0].has(fn))
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// run the function if it's first in line and not already running
|
|
53
|
+
const run = fn => {
|
|
54
|
+
if (running.has(fn) || !check(fn))
|
|
55
|
+
return false
|
|
56
|
+
running.add(fn)
|
|
57
|
+
fn(() => clear(fn))
|
|
58
|
+
return true
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const clear = fn => {
|
|
62
|
+
if (!running.has(fn))
|
|
63
|
+
return false
|
|
64
|
+
|
|
65
|
+
const { paths, dirs } = reservations.get(fn)
|
|
66
|
+
const next = new Set()
|
|
67
|
+
|
|
68
|
+
paths.forEach(path => {
|
|
69
|
+
const q = queues.get(path)
|
|
70
|
+
assert.equal(q[0], fn)
|
|
71
|
+
if (q.length === 1)
|
|
72
|
+
queues.delete(path)
|
|
73
|
+
else {
|
|
74
|
+
q.shift()
|
|
75
|
+
if (typeof q[0] === 'function')
|
|
76
|
+
next.add(q[0])
|
|
77
|
+
else
|
|
78
|
+
q[0].forEach(fn => next.add(fn))
|
|
79
|
+
}
|
|
80
|
+
})
|
|
81
|
+
|
|
82
|
+
dirs.forEach(dir => {
|
|
83
|
+
const q = queues.get(dir)
|
|
84
|
+
assert(q[0] instanceof Set)
|
|
85
|
+
if (q[0].size === 1 && q.length === 1) {
|
|
86
|
+
queues.delete(dir)
|
|
87
|
+
} else if (q[0].size === 1) {
|
|
88
|
+
q.shift()
|
|
89
|
+
|
|
90
|
+
// must be a function or else the Set would've been reused
|
|
91
|
+
next.add(q[0])
|
|
92
|
+
} else
|
|
93
|
+
q[0].delete(fn)
|
|
94
|
+
})
|
|
95
|
+
running.delete(fn)
|
|
96
|
+
|
|
97
|
+
next.forEach(fn => run(fn))
|
|
98
|
+
return true
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const reserve = (paths, fn) => {
|
|
102
|
+
const dirs = new Set(
|
|
103
|
+
paths.map(path => getDirs(path)).reduce((a, b) => a.concat(b))
|
|
104
|
+
)
|
|
105
|
+
reservations.set(fn, {dirs, paths})
|
|
106
|
+
paths.forEach(path => {
|
|
107
|
+
const q = queues.get(path)
|
|
108
|
+
if (!q)
|
|
109
|
+
queues.set(path, [fn])
|
|
110
|
+
else
|
|
111
|
+
q.push(fn)
|
|
112
|
+
})
|
|
113
|
+
dirs.forEach(dir => {
|
|
114
|
+
const q = queues.get(dir)
|
|
115
|
+
if (!q)
|
|
116
|
+
queues.set(dir, [new Set([fn])])
|
|
117
|
+
else if (q[q.length-1] instanceof Set)
|
|
118
|
+
q[q.length-1].add(fn)
|
|
119
|
+
else
|
|
120
|
+
q.push(new Set([fn]))
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
return run(fn)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return { check, reserve }
|
|
127
|
+
}
|
package/lib/read-entry.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
const types = require('./types.js')
|
|
3
3
|
const MiniPass = require('minipass')
|
|
4
|
+
const normPath = require('./normalize-windows-path.js')
|
|
4
5
|
|
|
5
6
|
const SLURP = Symbol('slurp')
|
|
6
7
|
module.exports = class ReadEntry extends MiniPass {
|
|
@@ -47,7 +48,7 @@ module.exports = class ReadEntry extends MiniPass {
|
|
|
47
48
|
this.ignore = true
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
this.path = header.path
|
|
51
|
+
this.path = normPath(header.path)
|
|
51
52
|
this.mode = header.mode
|
|
52
53
|
if (this.mode)
|
|
53
54
|
this.mode = this.mode & 0o7777
|
|
@@ -59,7 +60,7 @@ module.exports = class ReadEntry extends MiniPass {
|
|
|
59
60
|
this.mtime = header.mtime
|
|
60
61
|
this.atime = header.atime
|
|
61
62
|
this.ctime = header.ctime
|
|
62
|
-
this.linkpath = header.linkpath
|
|
63
|
+
this.linkpath = normPath(header.linkpath)
|
|
63
64
|
this.uname = header.uname
|
|
64
65
|
this.gname = header.gname
|
|
65
66
|
|
|
@@ -92,7 +93,7 @@ module.exports = class ReadEntry extends MiniPass {
|
|
|
92
93
|
// a global extended header, because that's weird.
|
|
93
94
|
if (ex[k] !== null && ex[k] !== undefined &&
|
|
94
95
|
!(global && k === 'path'))
|
|
95
|
-
this[k] = ex[k]
|
|
96
|
+
this[k] = k === 'path' || k === 'linkpath' ? normPath(ex[k]) : ex[k]
|
|
96
97
|
}
|
|
97
98
|
}
|
|
98
99
|
}
|
package/lib/replace.js
CHANGED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// unix absolute paths are also absolute on win32, so we use this for both
|
|
2
|
+
const { isAbsolute, parse } = require('path').win32
|
|
3
|
+
|
|
4
|
+
// returns [root, stripped]
|
|
5
|
+
module.exports = path => {
|
|
6
|
+
let r = ''
|
|
7
|
+
while (isAbsolute(path)) {
|
|
8
|
+
// windows will think that //x/y/z has a "root" of //x/y/
|
|
9
|
+
const root = path.charAt(0) === '/' ? '/' : parse(path).root
|
|
10
|
+
path = path.substr(root.length)
|
|
11
|
+
r += root
|
|
12
|
+
}
|
|
13
|
+
return [r, path]
|
|
14
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// this is the only approach that was significantly faster than using
|
|
2
|
+
// str.replace(/\/+$/, '') for strings ending with a lot of / chars and
|
|
3
|
+
// containing multiple / chars.
|
|
4
|
+
const batchStrings = [
|
|
5
|
+
'/'.repeat(1024),
|
|
6
|
+
'/'.repeat(512),
|
|
7
|
+
'/'.repeat(256),
|
|
8
|
+
'/'.repeat(128),
|
|
9
|
+
'/'.repeat(64),
|
|
10
|
+
'/'.repeat(32),
|
|
11
|
+
'/'.repeat(16),
|
|
12
|
+
'/'.repeat(8),
|
|
13
|
+
'/'.repeat(4),
|
|
14
|
+
'/'.repeat(2),
|
|
15
|
+
'/',
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
module.exports = str => {
|
|
19
|
+
for (const s of batchStrings) {
|
|
20
|
+
while (str.length >= s.length && str.slice(-1 * s.length) === s)
|
|
21
|
+
str = str.slice(0, -1 * s.length)
|
|
22
|
+
}
|
|
23
|
+
return str
|
|
24
|
+
}
|