tar 4.3.1 → 4.4.1

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 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/buffer.js ADDED
@@ -0,0 +1,11 @@
1
+ 'use strict'
2
+
3
+ // Buffer in node 4.x < 4.5.0 doesn't have working Buffer.from
4
+ // or Buffer.alloc, and Buffer in node 10 deprecated the ctor.
5
+ // .M, this is fine .\^/M..
6
+ let B = Buffer
7
+ /* istanbul ignore next */
8
+ if (!B.alloc) {
9
+ B = require('safe-buffer').Buffer
10
+ }
11
+ module.exports = B
package/lib/header.js CHANGED
@@ -4,6 +4,7 @@
4
4
  // the data could not be faithfully encoded in a simple header.
5
5
  // (Also, check header.needPax to see if it needs a pax header.)
6
6
 
7
+ const Buffer = require('./buffer.js')
7
8
  const types = require('./types.js')
8
9
  const pathModule = require('path')
9
10
  const large = require('./large-numbers.js')
package/lib/list.js CHANGED
@@ -1,5 +1,7 @@
1
1
  'use strict'
2
2
 
3
+ const Buffer = require('./buffer.js')
4
+
3
5
  // XXX: This shares a lot in common with extract.js
4
6
  // maybe some DRY opportunity here?
5
7
 
package/lib/pack.js CHANGED
@@ -1,5 +1,7 @@
1
1
  'use strict'
2
2
 
3
+ const Buffer = require('./buffer.js')
4
+
3
5
  // A readable tar stream creator
4
6
  // Technically, this is a transform stream that you write paths into,
5
7
  // and tar format comes out of.
@@ -89,6 +91,7 @@ const Pack = warner(class Pack extends MiniPass {
89
91
  this.noDirRecurse = !!opt.noDirRecurse
90
92
  this.follow = !!opt.follow
91
93
  this.noMtime = !!opt.noMtime
94
+ this.mtime = opt.mtime || null
92
95
 
93
96
  this.filter = typeof opt.filter === 'function' ? opt.filter : _ => true
94
97
 
@@ -293,7 +296,8 @@ const Pack = warner(class Pack extends MiniPass {
293
296
  portable: this.portable,
294
297
  linkCache: this.linkCache,
295
298
  statCache: this.statCache,
296
- noMtime: this.noMtime
299
+ noMtime: this.noMtime,
300
+ mtime: this.mtime
297
301
  }
298
302
  }
299
303
 
package/lib/parse.js CHANGED
@@ -30,7 +30,7 @@ const Entry = require('./read-entry.js')
30
30
  const Pax = require('./pax.js')
31
31
  const zlib = require('minizlib')
32
32
 
33
- const gzipHeader = new Buffer([0x1f, 0x8b])
33
+ const gzipHeader = Buffer.from([0x1f, 0x8b])
34
34
  const STATE = Symbol('state')
35
35
  const WRITEENTRY = Symbol('writeEntry')
36
36
  const READENTRY = Symbol('readEntry')
package/lib/pax.js CHANGED
@@ -1,4 +1,5 @@
1
1
  'use strict'
2
+ const Buffer = require('./buffer.js')
2
3
  const Header = require('./header.js')
3
4
  const path = require('path')
4
5
 
package/lib/replace.js CHANGED
@@ -1,4 +1,5 @@
1
1
  'use strict'
2
+ const Buffer = require('./buffer.js')
2
3
 
3
4
  // tar -r
4
5
  const hlo = require('./high-level-opt.js')
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.preserveOwner &&
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
  ||
@@ -259,20 +263,28 @@ class Unpack extends Parser {
259
263
  }
260
264
 
261
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
+
262
272
  if (entry.mtime && !this.noMtime) {
263
273
  actions++
264
- const fd = stream.fd
265
274
  const atime = entry.atime || new Date()
266
275
  const mtime = entry.mtime
267
- fs.futimes(fd, atime, mtime, done)
276
+ fs.futimes(fd, atime, mtime, er =>
277
+ er ? fs.utimes(abs, atime, mtime, er2 => done(er2 && er))
278
+ : done())
268
279
  }
269
280
 
270
281
  if (this[DOCHOWN](entry)) {
271
282
  actions++
272
- const fd = stream.fd
273
283
  const uid = this[UID](entry)
274
284
  const gid = this[GID](entry)
275
- fs.fchown(fd, uid, gid, done)
285
+ fs.fchown(fd, uid, gid, er =>
286
+ er ? fs.chown(abs, uid, gid, er2 => done(er2 && er))
287
+ : done())
276
288
  }
277
289
 
278
290
  done()
@@ -437,7 +449,8 @@ class UnpackSync extends Unpack {
437
449
 
438
450
  const oner = er => {
439
451
  try { fs.closeSync(fd) } catch (_) {}
440
- this[ONERROR](er, entry)
452
+ if (er)
453
+ this[ONERROR](er, entry)
441
454
  }
442
455
 
443
456
  let stream
@@ -460,17 +473,39 @@ class UnpackSync extends Unpack {
460
473
  })
461
474
 
462
475
  tx.on('end', _ => {
463
- try {
464
- if (entry.mtime && !this.noMtime)
465
- fs.futimesSync(fd, entry.atime || new Date(), entry.mtime)
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
+ }
466
492
 
467
- if (this[DOCHOWN](entry))
468
- fs.fchownSync(fd, this[UID](entry), this[GID](entry))
493
+ if (this[DOCHOWN](entry)) {
494
+ const uid = this[UID](entry)
495
+ const gid = this[GID](entry)
469
496
 
470
- fs.closeSync(fd)
471
- } catch (er) {
472
- return oner(er)
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
+ }
473
506
  }
507
+
508
+ oner(er)
474
509
  })
475
510
  }
476
511
 
@@ -1,4 +1,5 @@
1
1
  'use strict'
2
+ const Buffer = require('./buffer.js')
2
3
  const MiniPass = require('minipass')
3
4
  const Pax = require('./pax.js')
4
5
  const Header = require('./header.js')
@@ -45,6 +46,7 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
45
46
  this.strict = !!opt.strict
46
47
  this.noPax = !!opt.noPax
47
48
  this.noMtime = !!opt.noMtime
49
+ this.mtime = opt.mtime || null
48
50
 
49
51
  if (typeof opt.onwarn === 'function')
50
52
  this.on('warn', opt.onwarn)
@@ -115,7 +117,7 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
115
117
  uid: this.portable ? null : this.stat.uid,
116
118
  gid: this.portable ? null : this.stat.gid,
117
119
  size: this.stat.size,
118
- mtime: this.noMtime ? null : this.stat.mtime,
120
+ mtime: this.noMtime ? null : this.mtime || this.stat.mtime,
119
121
  type: this.type,
120
122
  uname: this.portable ? null :
121
123
  this.stat.uid === this.myuid ? this.myuser : '',
@@ -128,7 +130,7 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
128
130
  atime: this.portable ? null : this.header.atime,
129
131
  ctime: this.portable ? null : this.header.ctime,
130
132
  gid: this.portable ? null : this.header.gid,
131
- mtime: this.noMtime ? null : this.header.mtime,
133
+ mtime: this.noMtime ? null : this.mtime || this.header.mtime,
132
134
  path: this.path,
133
135
  linkpath: this.linkpath,
134
136
  size: this.header.size,
@@ -318,7 +320,7 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
318
320
  this.uname = this.portable ? null : readEntry.uname
319
321
  this.gname = this.portable ? null : readEntry.gname
320
322
  this.size = readEntry.size
321
- this.mtime = this.noMtime ? null : readEntry.mtime
323
+ this.mtime = this.noMtime ? null : opt.mtime || readEntry.mtime
322
324
  this.atime = this.portable ? null : readEntry.atime
323
325
  this.ctime = this.portable ? null : readEntry.ctime
324
326
  this.linkpath = readEntry.linkpath
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "Isaac Z. Schlueter <i@izs.me> (http://blog.izs.me/)",
3
3
  "name": "tar",
4
4
  "description": "tar for node",
5
- "version": "4.3.1",
5
+ "version": "4.4.1",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/npm/node-tar.git"
@@ -17,19 +17,20 @@
17
17
  },
18
18
  "dependencies": {
19
19
  "chownr": "^1.0.1",
20
- "fs-minipass": "^1.2.3",
21
- "minipass": "^2.2.1",
20
+ "fs-minipass": "^1.2.5",
21
+ "minipass": "^2.2.4",
22
22
  "minizlib": "^1.1.0",
23
23
  "mkdirp": "^0.5.0",
24
+ "safe-buffer": "^5.1.1",
24
25
  "yallist": "^3.0.2"
25
26
  },
26
27
  "devDependencies": {
27
28
  "chmodr": "^1.0.2",
28
- "end-of-stream": "^1.4.0",
29
+ "end-of-stream": "^1.4.1",
29
30
  "events-to-array": "^1.1.2",
30
31
  "mutate-fs": "^2.1.1",
31
32
  "rimraf": "^2.6.2",
32
- "tap": "^11.0.0-rc.3",
33
+ "tap": "^11.1.3",
33
34
  "tar-fs": "^1.16.0",
34
35
  "tar-stream": "^1.5.2"
35
36
  },
Binary file