tar 4.3.0 → 4.4.0
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/README.md +13 -0
- package/lib/pack.js +3 -1
- package/lib/unpack.js +57 -18
- package/lib/write-entry.js +4 -3
- package/package.json +1 -1
- package/lib/.unpack.js.swp +0 -0
package/README.md
CHANGED
|
@@ -322,6 +322,8 @@ The following options are supported:
|
|
|
322
322
|
the archive entry. If a falsey value is provided, then the entry is
|
|
323
323
|
written to disk as normal. (To exclude items from extraction, use
|
|
324
324
|
the `filter` option described above.)
|
|
325
|
+
- `onentry` A function that gets called with `(entry)` for each entry
|
|
326
|
+
that passes the filter.
|
|
325
327
|
|
|
326
328
|
The following options are mostly internal, but can be modified in some
|
|
327
329
|
advanced use cases, such as re-using caches between runs.
|
|
@@ -426,6 +428,8 @@ The following options are supported:
|
|
|
426
428
|
Note that this prevents using other mtime-based features like
|
|
427
429
|
`tar.update` or the `keepNewer` option with the resulting tar archive.
|
|
428
430
|
[Alias: `m`, `no-mtime`]
|
|
431
|
+
- `mtime` Set to a `Date` object to force a specific `mtime` for
|
|
432
|
+
everything added to the archive. Overridden by `noMtime`.
|
|
429
433
|
|
|
430
434
|
### tar.r(options, fileList, callback) [alias: tar.replace]
|
|
431
435
|
|
|
@@ -475,6 +479,8 @@ The following options are supported:
|
|
|
475
479
|
Note that this prevents using other mtime-based features like
|
|
476
480
|
`tar.update` or the `keepNewer` option with the resulting tar archive.
|
|
477
481
|
[Alias: `m`, `no-mtime`]
|
|
482
|
+
- `mtime` Set to a `Date` object to force a specific `mtime` for
|
|
483
|
+
everything added to the archive. Overridden by `noMtime`.
|
|
478
484
|
|
|
479
485
|
|
|
480
486
|
## Low-Level API
|
|
@@ -525,6 +531,8 @@ The following options are supported:
|
|
|
525
531
|
- `noMtime` Set to true to omit writing `mtime` values for entries.
|
|
526
532
|
Note that this prevents using other mtime-based features like
|
|
527
533
|
`tar.update` or the `keepNewer` option with the resulting tar archive.
|
|
534
|
+
- `mtime` Set to a `Date` object to force a specific `mtime` for
|
|
535
|
+
everything added to the archive. Overridden by `noMtime`.
|
|
528
536
|
|
|
529
537
|
|
|
530
538
|
#### add(path)
|
|
@@ -621,6 +629,11 @@ Most unpack errors will cause a `warn` event to be emitted. If the
|
|
|
621
629
|
the archive entry. If a falsey value is provided, then the entry is
|
|
622
630
|
written to disk as normal. (To exclude items from extraction, use
|
|
623
631
|
the `filter` option described above.)
|
|
632
|
+
- `strict` Treat warnings as crash-worthy errors. Default false.
|
|
633
|
+
- `onentry` A function that gets called with `(entry)` for each entry
|
|
634
|
+
that passes the filter.
|
|
635
|
+
- `onwarn` A function that will get called with `(message, data)` for
|
|
636
|
+
any warnings encountered.
|
|
624
637
|
|
|
625
638
|
### class tar.Unpack.Sync
|
|
626
639
|
|
package/lib/pack.js
CHANGED
|
@@ -89,6 +89,7 @@ const Pack = warner(class Pack extends MiniPass {
|
|
|
89
89
|
this.noDirRecurse = !!opt.noDirRecurse
|
|
90
90
|
this.follow = !!opt.follow
|
|
91
91
|
this.noMtime = !!opt.noMtime
|
|
92
|
+
this.mtime = opt.mtime || null
|
|
92
93
|
|
|
93
94
|
this.filter = typeof opt.filter === 'function' ? opt.filter : _ => true
|
|
94
95
|
|
|
@@ -293,7 +294,8 @@ const Pack = warner(class Pack extends MiniPass {
|
|
|
293
294
|
portable: this.portable,
|
|
294
295
|
linkCache: this.linkCache,
|
|
295
296
|
statCache: this.statCache,
|
|
296
|
-
noMtime: this.noMtime
|
|
297
|
+
noMtime: this.noMtime,
|
|
298
|
+
mtime: this.mtime
|
|
297
299
|
}
|
|
298
300
|
}
|
|
299
301
|
|
package/lib/unpack.js
CHANGED
|
@@ -49,8 +49,6 @@ class Unpack extends Parser {
|
|
|
49
49
|
this[MAYBECLOSE]()
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
opt.onentry = entry => this[ONENTRY](entry)
|
|
53
|
-
|
|
54
52
|
super(opt)
|
|
55
53
|
|
|
56
54
|
this.transform = typeof opt.transform === 'function' ? opt.transform : null
|
|
@@ -90,6 +88,10 @@ class Unpack extends Parser {
|
|
|
90
88
|
this.processGid = (this.preserveOwner || this.setOwner) && process.getgid ?
|
|
91
89
|
process.getgid() : null
|
|
92
90
|
|
|
91
|
+
// mostly just for testing, but useful in some cases.
|
|
92
|
+
// Forcibly trigger a chown on every entry, no matter what
|
|
93
|
+
this.forceChown = opt.forceChown === true
|
|
94
|
+
|
|
93
95
|
// turn ><?| in filenames into 0xf000-higher encoded forms
|
|
94
96
|
this.win32 = !!opt.win32 || process.platform === 'win32'
|
|
95
97
|
|
|
@@ -118,6 +120,7 @@ class Unpack extends Parser {
|
|
|
118
120
|
// default mode for dirs created as parents
|
|
119
121
|
this.dmode = opt.dmode || (0o0777 & (~this.umask))
|
|
120
122
|
this.fmode = opt.fmode || (0o0666 & (~this.umask))
|
|
123
|
+
this.on('entry', entry => this[ONENTRY](entry))
|
|
121
124
|
}
|
|
122
125
|
|
|
123
126
|
[MAYBECLOSE] () {
|
|
@@ -225,7 +228,8 @@ class Unpack extends Parser {
|
|
|
225
228
|
[DOCHOWN] (entry) {
|
|
226
229
|
// in preserve owner mode, chown if the entry doesn't match process
|
|
227
230
|
// in set owner mode, chown if setting doesn't match process
|
|
228
|
-
return this.
|
|
231
|
+
return this.forceChown ||
|
|
232
|
+
this.preserveOwner &&
|
|
229
233
|
( typeof entry.uid === 'number' && entry.uid !== this.processUid ||
|
|
230
234
|
typeof entry.gid === 'number' && entry.gid !== this.processGid )
|
|
231
235
|
||
|
|
@@ -251,24 +255,36 @@ class Unpack extends Parser {
|
|
|
251
255
|
|
|
252
256
|
let actions = 1
|
|
253
257
|
const done = er => {
|
|
254
|
-
if (er)
|
|
255
|
-
this[ONERROR](er, entry)
|
|
256
|
-
actions = 1
|
|
257
|
-
}
|
|
258
|
+
if (er)
|
|
259
|
+
return this[ONERROR](er, entry)
|
|
258
260
|
|
|
259
261
|
if (--actions === 0)
|
|
260
262
|
fs.close(stream.fd, _ => this[UNPEND]())
|
|
261
263
|
}
|
|
262
264
|
|
|
263
265
|
stream.on('finish', _ => {
|
|
266
|
+
// if futimes fails, try utimes
|
|
267
|
+
// if utimes fails, fail with the original error
|
|
268
|
+
// same for fchown/chown
|
|
269
|
+
const abs = entry.absolute
|
|
270
|
+
const fd = stream.fd
|
|
271
|
+
|
|
264
272
|
if (entry.mtime && !this.noMtime) {
|
|
265
273
|
actions++
|
|
266
|
-
|
|
274
|
+
const atime = entry.atime || new Date()
|
|
275
|
+
const mtime = entry.mtime
|
|
276
|
+
fs.futimes(fd, atime, mtime, er =>
|
|
277
|
+
er ? fs.utimes(abs, atime, mtime, er2 => done(er2 && er))
|
|
278
|
+
: done())
|
|
267
279
|
}
|
|
268
280
|
|
|
269
281
|
if (this[DOCHOWN](entry)) {
|
|
270
282
|
actions++
|
|
271
|
-
|
|
283
|
+
const uid = this[UID](entry)
|
|
284
|
+
const gid = this[GID](entry)
|
|
285
|
+
fs.fchown(fd, uid, gid, er =>
|
|
286
|
+
er ? fs.chown(abs, uid, gid, er2 => done(er2 && er))
|
|
287
|
+
: done())
|
|
272
288
|
}
|
|
273
289
|
|
|
274
290
|
done()
|
|
@@ -433,7 +449,8 @@ class UnpackSync extends Unpack {
|
|
|
433
449
|
|
|
434
450
|
const oner = er => {
|
|
435
451
|
try { fs.closeSync(fd) } catch (_) {}
|
|
436
|
-
|
|
452
|
+
if (er)
|
|
453
|
+
this[ONERROR](er, entry)
|
|
437
454
|
}
|
|
438
455
|
|
|
439
456
|
let stream
|
|
@@ -456,17 +473,39 @@ class UnpackSync extends Unpack {
|
|
|
456
473
|
})
|
|
457
474
|
|
|
458
475
|
tx.on('end', _ => {
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
476
|
+
let er = null
|
|
477
|
+
// try both, falling futimes back to utimes
|
|
478
|
+
// if either fails, handle the first error
|
|
479
|
+
if (entry.mtime && !this.noMtime) {
|
|
480
|
+
const atime = entry.atime || new Date()
|
|
481
|
+
const mtime = entry.mtime
|
|
482
|
+
try {
|
|
483
|
+
fs.futimesSync(fd, atime, mtime)
|
|
484
|
+
} catch (futimeser) {
|
|
485
|
+
try {
|
|
486
|
+
fs.utimesSync(entry.absolute, atime, mtime)
|
|
487
|
+
} catch (utimeser) {
|
|
488
|
+
er = futimeser
|
|
489
|
+
}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
462
492
|
|
|
463
|
-
|
|
464
|
-
|
|
493
|
+
if (this[DOCHOWN](entry)) {
|
|
494
|
+
const uid = this[UID](entry)
|
|
495
|
+
const gid = this[GID](entry)
|
|
465
496
|
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
497
|
+
try {
|
|
498
|
+
fs.fchownSync(fd, uid, gid)
|
|
499
|
+
} catch (fchowner) {
|
|
500
|
+
try {
|
|
501
|
+
fs.chownSync(entry.absolute, uid, gid)
|
|
502
|
+
} catch (chowner) {
|
|
503
|
+
er = er || fchowner
|
|
504
|
+
}
|
|
505
|
+
}
|
|
469
506
|
}
|
|
507
|
+
|
|
508
|
+
oner(er)
|
|
470
509
|
})
|
|
471
510
|
}
|
|
472
511
|
|
package/lib/write-entry.js
CHANGED
|
@@ -45,6 +45,7 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
|
|
|
45
45
|
this.strict = !!opt.strict
|
|
46
46
|
this.noPax = !!opt.noPax
|
|
47
47
|
this.noMtime = !!opt.noMtime
|
|
48
|
+
this.mtime = opt.mtime || null
|
|
48
49
|
|
|
49
50
|
if (typeof opt.onwarn === 'function')
|
|
50
51
|
this.on('warn', opt.onwarn)
|
|
@@ -115,7 +116,7 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
|
|
|
115
116
|
uid: this.portable ? null : this.stat.uid,
|
|
116
117
|
gid: this.portable ? null : this.stat.gid,
|
|
117
118
|
size: this.stat.size,
|
|
118
|
-
mtime: this.noMtime ? null : this.stat.mtime,
|
|
119
|
+
mtime: this.noMtime ? null : this.mtime || this.stat.mtime,
|
|
119
120
|
type: this.type,
|
|
120
121
|
uname: this.portable ? null :
|
|
121
122
|
this.stat.uid === this.myuid ? this.myuser : '',
|
|
@@ -128,7 +129,7 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
|
|
|
128
129
|
atime: this.portable ? null : this.header.atime,
|
|
129
130
|
ctime: this.portable ? null : this.header.ctime,
|
|
130
131
|
gid: this.portable ? null : this.header.gid,
|
|
131
|
-
mtime: this.noMtime ? null : this.header.mtime,
|
|
132
|
+
mtime: this.noMtime ? null : this.mtime || this.header.mtime,
|
|
132
133
|
path: this.path,
|
|
133
134
|
linkpath: this.linkpath,
|
|
134
135
|
size: this.header.size,
|
|
@@ -318,7 +319,7 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
|
|
|
318
319
|
this.uname = this.portable ? null : readEntry.uname
|
|
319
320
|
this.gname = this.portable ? null : readEntry.gname
|
|
320
321
|
this.size = readEntry.size
|
|
321
|
-
this.mtime = this.noMtime ? null : readEntry.mtime
|
|
322
|
+
this.mtime = this.noMtime ? null : opt.mtime || readEntry.mtime
|
|
322
323
|
this.atime = this.portable ? null : readEntry.atime
|
|
323
324
|
this.ctime = this.portable ? null : readEntry.ctime
|
|
324
325
|
this.linkpath = readEntry.linkpath
|
package/package.json
CHANGED
package/lib/.unpack.js.swp
DELETED
|
Binary file
|