tar 3.1.5 → 3.1.9
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/parse.js +11 -3
- package/lib/read-entry.js +2 -1
- package/lib/unpack.js +54 -20
- package/lib/write-entry.js +2 -1
- package/package.json +1 -1
package/lib/parse.js
CHANGED
|
@@ -56,19 +56,27 @@ const BUFFERCONCAT = Symbol('bufferConcat')
|
|
|
56
56
|
const MAYBEEND = Symbol('maybeEnd')
|
|
57
57
|
const WRITING = Symbol('writing')
|
|
58
58
|
const ABORTED = Symbol('aborted')
|
|
59
|
+
const DONE = Symbol('onDone')
|
|
59
60
|
|
|
60
|
-
|
|
61
|
+
const noop = _ => true
|
|
61
62
|
|
|
62
63
|
module.exports = warner(class Parser extends EE {
|
|
63
64
|
constructor (opt) {
|
|
64
|
-
const start = process.hrtime()
|
|
65
65
|
opt = opt || {}
|
|
66
66
|
super(opt)
|
|
67
67
|
|
|
68
|
+
if (opt.ondone)
|
|
69
|
+
this.on(DONE, opt.ondone)
|
|
70
|
+
else
|
|
71
|
+
this.on(DONE, _ => (this.emit('end'), this.emit('close')))
|
|
72
|
+
|
|
68
73
|
this.strict = !!opt.strict
|
|
69
74
|
this.maxMetaEntrySize = opt.maxMetaEntrySize || maxMetaEntrySize
|
|
70
75
|
this.filter = typeof opt.filter === 'function' ? opt.filter : noop
|
|
71
76
|
|
|
77
|
+
// have to set this so that streams are ok piping into it
|
|
78
|
+
this.writable = true
|
|
79
|
+
|
|
72
80
|
this[QUEUE] = new Yallist()
|
|
73
81
|
this[BUFFER] = null
|
|
74
82
|
this[READENTRY] = null
|
|
@@ -321,7 +329,7 @@ module.exports = warner(class Parser extends EE {
|
|
|
321
329
|
entry.write(this[BUFFER])
|
|
322
330
|
entry.end()
|
|
323
331
|
}
|
|
324
|
-
this[EMIT](
|
|
332
|
+
this[EMIT](DONE)
|
|
325
333
|
}
|
|
326
334
|
}
|
|
327
335
|
|
package/lib/read-entry.js
CHANGED
|
@@ -9,7 +9,8 @@ module.exports = class ReadEntry extends MiniPass {
|
|
|
9
9
|
this.extended = ex
|
|
10
10
|
this.globalExtended = gex
|
|
11
11
|
this.header = header
|
|
12
|
-
this.
|
|
12
|
+
this.startBlockSize = 512 * Math.ceil(header.size / 512)
|
|
13
|
+
this.blockRemain = this.startBlockSize
|
|
13
14
|
this.remain = header.size
|
|
14
15
|
this.type = header.type
|
|
15
16
|
this.meta = false
|
package/lib/unpack.js
CHANGED
|
@@ -28,19 +28,22 @@ const UNPEND = Symbol('unpend')
|
|
|
28
28
|
const ENDED = Symbol('ended')
|
|
29
29
|
const MAYBECLOSE = Symbol('maybeClose')
|
|
30
30
|
const SKIP = Symbol('skip')
|
|
31
|
+
const DOCHOWN = Symbol('doChown')
|
|
31
32
|
|
|
32
33
|
class Unpack extends Parser {
|
|
33
34
|
constructor (opt) {
|
|
34
|
-
super(opt)
|
|
35
35
|
if (!opt)
|
|
36
36
|
opt = {}
|
|
37
37
|
|
|
38
|
-
|
|
39
|
-
this[ENDED] = false
|
|
40
|
-
this.on('end', _ => {
|
|
38
|
+
opt.ondone = _ => {
|
|
41
39
|
this[ENDED] = true
|
|
42
40
|
this[MAYBECLOSE]()
|
|
43
|
-
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
super(opt)
|
|
44
|
+
|
|
45
|
+
this[PENDING] = 0
|
|
46
|
+
this[ENDED] = false
|
|
44
47
|
|
|
45
48
|
this.dirCache = opt.dirCache || new Map()
|
|
46
49
|
|
|
@@ -49,6 +52,9 @@ class Unpack extends Parser {
|
|
|
49
52
|
else
|
|
50
53
|
this.preserveOwner = !!opt.preserveOwner
|
|
51
54
|
|
|
55
|
+
this.processUid = this.preserveOwner ? process.getuid() : null
|
|
56
|
+
this.processGid = this.preserveOwner ? process.getgid() : null
|
|
57
|
+
|
|
52
58
|
// turn ><?| in filenames into 0xf000-higher encoded forms
|
|
53
59
|
this.win32 = !!opt.win32 || process.platform === 'win32'
|
|
54
60
|
|
|
@@ -165,18 +171,34 @@ class Unpack extends Parser {
|
|
|
165
171
|
}, cb)
|
|
166
172
|
}
|
|
167
173
|
|
|
174
|
+
[DOCHOWN] (entry) {
|
|
175
|
+
return this.preserveOwner &&
|
|
176
|
+
( typeof entry.uid === 'number' && entry.uid !== this.processUid ||
|
|
177
|
+
typeof entry.gid === 'number' && entry.gid !== this.processGid )
|
|
178
|
+
}
|
|
179
|
+
|
|
168
180
|
[FILE] (entry) {
|
|
169
181
|
const mode = entry.mode & 0o7777 || this.fmode
|
|
170
182
|
const stream = fs.createWriteStream(entry.absolute, { mode: mode })
|
|
171
183
|
stream.on('error', er => this[ONERROR](er, entry))
|
|
184
|
+
|
|
185
|
+
const queue = []
|
|
186
|
+
const processQueue = _ => {
|
|
187
|
+
const action = queue.shift()
|
|
188
|
+
if (action)
|
|
189
|
+
action(processQueue)
|
|
190
|
+
else
|
|
191
|
+
this[UNPEND]()
|
|
192
|
+
}
|
|
193
|
+
|
|
172
194
|
stream.on('close', _ => {
|
|
173
195
|
if (entry.mtime && !this.noMtime)
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
196
|
+
queue.push(cb =>
|
|
197
|
+
fs.utimes(entry.absolute, entry.atime || new Date(), entry.mtime, cb))
|
|
198
|
+
if (this[DOCHOWN](entry))
|
|
199
|
+
queue.push(cb =>
|
|
200
|
+
fs.chown(entry.absolute, entry.uid, entry.gid || this.processGid, cb))
|
|
201
|
+
processQueue()
|
|
180
202
|
})
|
|
181
203
|
entry.pipe(stream)
|
|
182
204
|
}
|
|
@@ -186,14 +208,26 @@ class Unpack extends Parser {
|
|
|
186
208
|
this[MKDIR](entry.absolute, mode, er => {
|
|
187
209
|
if (er)
|
|
188
210
|
return this[ONERROR](er, entry)
|
|
211
|
+
|
|
212
|
+
const queue = []
|
|
213
|
+
const processQueue = _ => {
|
|
214
|
+
const action = queue.shift()
|
|
215
|
+
if (action)
|
|
216
|
+
action(processQueue)
|
|
217
|
+
else {
|
|
218
|
+
this[UNPEND]()
|
|
219
|
+
entry.resume()
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
|
|
189
223
|
if (entry.mtime && !this.noMtime)
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
224
|
+
queue.push(cb =>
|
|
225
|
+
fs.utimes(entry.absolute, entry.atime || new Date(), entry.mtime, cb))
|
|
226
|
+
if (this[DOCHOWN](entry))
|
|
227
|
+
queue.push(cb =>
|
|
228
|
+
fs.chown(entry.absolute, entry.uid, entry.gid || process.getgid(), cb))
|
|
229
|
+
|
|
230
|
+
processQueue()
|
|
197
231
|
})
|
|
198
232
|
}
|
|
199
233
|
|
|
@@ -328,7 +362,7 @@ class UnpackSync extends Unpack {
|
|
|
328
362
|
fs.futimesSync(fd, entry.atime || new Date(), entry.mtime)
|
|
329
363
|
} catch (er) {}
|
|
330
364
|
}
|
|
331
|
-
if (entry
|
|
365
|
+
if (this[DOCHOWN](entry)) {
|
|
332
366
|
try {
|
|
333
367
|
fs.fchownSync(fd, entry.uid, entry.gid || process.getgid())
|
|
334
368
|
} catch (er) {}
|
|
@@ -348,7 +382,7 @@ class UnpackSync extends Unpack {
|
|
|
348
382
|
fs.utimesSync(entry.absolute, entry.atime || new Date(), entry.mtime)
|
|
349
383
|
} catch (er) {}
|
|
350
384
|
}
|
|
351
|
-
if (entry
|
|
385
|
+
if (this[DOCHOWN](entry)) {
|
|
352
386
|
try {
|
|
353
387
|
fs.chownSync(entry.absolute, entry.uid, entry.gid || process.getgid())
|
|
354
388
|
} catch (er) {}
|
package/lib/write-entry.js
CHANGED
|
@@ -295,6 +295,7 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
|
|
|
295
295
|
opt = opt || {}
|
|
296
296
|
super(opt)
|
|
297
297
|
this.readEntry = readEntry
|
|
298
|
+
this.type = readEntry.type
|
|
298
299
|
this.path = readEntry.path
|
|
299
300
|
this.mode = readEntry.mode
|
|
300
301
|
if (this.mode)
|
|
@@ -329,7 +330,7 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
|
|
|
329
330
|
}
|
|
330
331
|
|
|
331
332
|
this.remain = readEntry.size
|
|
332
|
-
this.blockRemain = readEntry.
|
|
333
|
+
this.blockRemain = readEntry.startBlockSize
|
|
333
334
|
|
|
334
335
|
this.header = new Header({
|
|
335
336
|
path: this.path,
|
package/package.json
CHANGED