tar 4.4.2 → 4.4.6
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 +6 -1
- package/lib/header.js +20 -4
- package/lib/mode-fix.js +14 -0
- package/lib/pack.js +1 -0
- package/lib/parse.js +1 -1
- package/lib/unpack.js +47 -4
- package/lib/write-entry.js +13 -4
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -230,6 +230,9 @@ The following options are supported:
|
|
|
230
230
|
Note that this prevents using other mtime-based features like
|
|
231
231
|
`tar.update` or the `keepNewer` option with the resulting tar archive.
|
|
232
232
|
[Alias: `m`, `no-mtime`]
|
|
233
|
+
- `mtime` Set to a `Date` object to force a specific `mtime` for
|
|
234
|
+
everything added to the archive. Overridden by `noMtime`.
|
|
235
|
+
|
|
233
236
|
|
|
234
237
|
The following options are mostly internal, but can be modified in some
|
|
235
238
|
advanced use cases, such as re-using caches between runs.
|
|
@@ -534,7 +537,6 @@ The following options are supported:
|
|
|
534
537
|
- `mtime` Set to a `Date` object to force a specific `mtime` for
|
|
535
538
|
everything added to the archive. Overridden by `noMtime`.
|
|
536
539
|
|
|
537
|
-
|
|
538
540
|
#### add(path)
|
|
539
541
|
|
|
540
542
|
Adds an entry to the archive. Returns the Pack stream.
|
|
@@ -784,6 +786,9 @@ The following options are supported:
|
|
|
784
786
|
- `noMtime` Set to true to omit writing `mtime` values for entries.
|
|
785
787
|
Note that this prevents using other mtime-based features like
|
|
786
788
|
`tar.update` or the `keepNewer` option with the resulting tar archive.
|
|
789
|
+
- `umask` Set to restrict the modes on the entries in the archive,
|
|
790
|
+
somewhat like how umask works on file creation. Defaults to
|
|
791
|
+
`process.umask()` on unix systems, or `0o22` on Windows.
|
|
787
792
|
|
|
788
793
|
#### warn(message, data)
|
|
789
794
|
|
package/lib/header.js
CHANGED
|
@@ -6,13 +6,14 @@
|
|
|
6
6
|
|
|
7
7
|
const Buffer = require('./buffer.js')
|
|
8
8
|
const types = require('./types.js')
|
|
9
|
-
const pathModule = require('path')
|
|
9
|
+
const pathModule = require('path').posix
|
|
10
10
|
const large = require('./large-numbers.js')
|
|
11
11
|
|
|
12
|
+
const SLURP = Symbol('slurp')
|
|
12
13
|
const TYPE = Symbol('type')
|
|
13
14
|
|
|
14
15
|
class Header {
|
|
15
|
-
constructor (data, off) {
|
|
16
|
+
constructor (data, off, ex, gex) {
|
|
16
17
|
this.cksumValid = false
|
|
17
18
|
this.needPax = false
|
|
18
19
|
this.nullBlock = false
|
|
@@ -35,12 +36,12 @@ class Header {
|
|
|
35
36
|
this.ctime = null
|
|
36
37
|
|
|
37
38
|
if (Buffer.isBuffer(data))
|
|
38
|
-
this.decode(data, off || 0)
|
|
39
|
+
this.decode(data, off || 0, ex, gex)
|
|
39
40
|
else if (data)
|
|
40
41
|
this.set(data)
|
|
41
42
|
}
|
|
42
43
|
|
|
43
|
-
decode (buf, off) {
|
|
44
|
+
decode (buf, off, ex, gex) {
|
|
44
45
|
if (!off)
|
|
45
46
|
off = 0
|
|
46
47
|
|
|
@@ -55,6 +56,11 @@ class Header {
|
|
|
55
56
|
this.mtime = decDate(buf, off + 136, 12)
|
|
56
57
|
this.cksum = decNumber(buf, off + 148, 12)
|
|
57
58
|
|
|
59
|
+
// if we have extended or global extended headers, apply them now
|
|
60
|
+
// See https://github.com/npm/node-tar/pull/187
|
|
61
|
+
this[SLURP](ex)
|
|
62
|
+
this[SLURP](gex, true)
|
|
63
|
+
|
|
58
64
|
// old tar versions marked dirs as a file with a trailing /
|
|
59
65
|
this[TYPE] = decString(buf, off + 156, 1)
|
|
60
66
|
if (this[TYPE] === '')
|
|
@@ -101,6 +107,16 @@ class Header {
|
|
|
101
107
|
this.nullBlock = true
|
|
102
108
|
}
|
|
103
109
|
|
|
110
|
+
[SLURP] (ex, global) {
|
|
111
|
+
for (let k in ex) {
|
|
112
|
+
// we slurp in everything except for the path attribute in
|
|
113
|
+
// a global extended header, because that's weird.
|
|
114
|
+
if (ex[k] !== null && ex[k] !== undefined &&
|
|
115
|
+
!(global && k === 'path'))
|
|
116
|
+
this[k] = ex[k]
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
104
120
|
encode (buf, off) {
|
|
105
121
|
if (!buf) {
|
|
106
122
|
buf = this.block = Buffer.alloc(512)
|
package/lib/mode-fix.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
module.exports = (mode, isDir) => {
|
|
3
|
+
mode &= 0o7777
|
|
4
|
+
// if dirs are readable, then they should be listable
|
|
5
|
+
if (isDir) {
|
|
6
|
+
if (mode & 0o400)
|
|
7
|
+
mode |= 0o100
|
|
8
|
+
if (mode & 0o40)
|
|
9
|
+
mode |= 0o10
|
|
10
|
+
if (mode & 0o4)
|
|
11
|
+
mode |= 0o1
|
|
12
|
+
}
|
|
13
|
+
return mode
|
|
14
|
+
}
|
package/lib/pack.js
CHANGED
|
@@ -71,6 +71,7 @@ const Pack = warner(class Pack extends MiniPass {
|
|
|
71
71
|
this.linkCache = opt.linkCache || new Map()
|
|
72
72
|
this.statCache = opt.statCache || new Map()
|
|
73
73
|
this.readdirCache = opt.readdirCache || new Map()
|
|
74
|
+
|
|
74
75
|
this[WRITEENTRYCLASS] = WriteEntry
|
|
75
76
|
if (typeof opt.onwarn === 'function')
|
|
76
77
|
this.on('warn', opt.onwarn)
|
package/lib/parse.js
CHANGED
|
@@ -101,7 +101,7 @@ module.exports = warner(class Parser extends EE {
|
|
|
101
101
|
}
|
|
102
102
|
|
|
103
103
|
[CONSUMEHEADER] (chunk, position) {
|
|
104
|
-
const header = new Header(chunk, position)
|
|
104
|
+
const header = new Header(chunk, position, this[EX], this[GEX])
|
|
105
105
|
|
|
106
106
|
if (header.nullBlock)
|
|
107
107
|
this[EMIT]('nullBlock')
|
package/lib/unpack.js
CHANGED
|
@@ -33,6 +33,45 @@ const SKIP = Symbol('skip')
|
|
|
33
33
|
const DOCHOWN = Symbol('doChown')
|
|
34
34
|
const UID = Symbol('uid')
|
|
35
35
|
const GID = Symbol('gid')
|
|
36
|
+
const crypto = require('crypto')
|
|
37
|
+
|
|
38
|
+
// Unlinks on Windows are not atomic.
|
|
39
|
+
//
|
|
40
|
+
// This means that if you have a file entry, followed by another
|
|
41
|
+
// file entry with an identical name, and you cannot re-use the file
|
|
42
|
+
// (because it's a hardlink, or because unlink:true is set, or it's
|
|
43
|
+
// Windows, which does not have useful nlink values), then the unlink
|
|
44
|
+
// will be committed to the disk AFTER the new file has been written
|
|
45
|
+
// over the old one, deleting the new file.
|
|
46
|
+
//
|
|
47
|
+
// To work around this, on Windows systems, we rename the file and then
|
|
48
|
+
// delete the renamed file. It's a sloppy kludge, but frankly, I do not
|
|
49
|
+
// know of a better way to do this, given windows' non-atomic unlink
|
|
50
|
+
// semantics.
|
|
51
|
+
//
|
|
52
|
+
// See: https://github.com/npm/node-tar/issues/183
|
|
53
|
+
/* istanbul ignore next */
|
|
54
|
+
const unlinkFile = (path, cb) => {
|
|
55
|
+
if (process.platform !== 'win32')
|
|
56
|
+
return fs.unlink(path, cb)
|
|
57
|
+
|
|
58
|
+
const name = path + '.DELETE.' + crypto.randomBytes(16).toString('hex')
|
|
59
|
+
fs.rename(path, name, er => {
|
|
60
|
+
if (er)
|
|
61
|
+
return cb(er)
|
|
62
|
+
fs.unlink(name, cb)
|
|
63
|
+
})
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/* istanbul ignore next */
|
|
67
|
+
const unlinkFileSync = path => {
|
|
68
|
+
if (process.platform !== 'win32')
|
|
69
|
+
return fs.unlinkSync(path)
|
|
70
|
+
|
|
71
|
+
const name = path + '.DELETE.' + crypto.randomBytes(16).toString('hex')
|
|
72
|
+
fs.renameSync(path, name)
|
|
73
|
+
fs.unlinkSync(name)
|
|
74
|
+
}
|
|
36
75
|
|
|
37
76
|
// this.gid, entry.gid, this.processUid
|
|
38
77
|
const uint32 = (a, b, c) =>
|
|
@@ -292,8 +331,10 @@ class Unpack extends Parser {
|
|
|
292
331
|
})
|
|
293
332
|
|
|
294
333
|
const tx = this.transform ? this.transform(entry) || entry : entry
|
|
295
|
-
if (tx !== entry)
|
|
334
|
+
if (tx !== entry) {
|
|
335
|
+
tx.on('error', er => this[ONERROR](er, entry))
|
|
296
336
|
entry.pipe(tx)
|
|
337
|
+
}
|
|
297
338
|
tx.pipe(stream)
|
|
298
339
|
}
|
|
299
340
|
|
|
@@ -383,7 +424,7 @@ class Unpack extends Parser {
|
|
|
383
424
|
} else
|
|
384
425
|
fs.rmdir(entry.absolute, er => this[MAKEFS](er, entry))
|
|
385
426
|
} else
|
|
386
|
-
|
|
427
|
+
unlinkFile(entry.absolute, er => this[MAKEFS](er, entry))
|
|
387
428
|
})
|
|
388
429
|
})
|
|
389
430
|
}
|
|
@@ -445,7 +486,7 @@ class UnpackSync extends Unpack {
|
|
|
445
486
|
} else
|
|
446
487
|
fs.rmdirSync(entry.absolute)
|
|
447
488
|
} else
|
|
448
|
-
|
|
489
|
+
unlinkFileSync(entry.absolute)
|
|
449
490
|
return this[MAKEFS](null, entry)
|
|
450
491
|
} catch (er) {
|
|
451
492
|
return this[ONERROR](er, entry)
|
|
@@ -473,8 +514,10 @@ class UnpackSync extends Unpack {
|
|
|
473
514
|
return oner(er)
|
|
474
515
|
}
|
|
475
516
|
const tx = this.transform ? this.transform(entry) || entry : entry
|
|
476
|
-
if (tx !== entry)
|
|
517
|
+
if (tx !== entry) {
|
|
518
|
+
tx.on('error', er => this[ONERROR](er, entry))
|
|
477
519
|
entry.pipe(tx)
|
|
520
|
+
}
|
|
478
521
|
|
|
479
522
|
tx.on('data', chunk => {
|
|
480
523
|
try {
|
package/lib/write-entry.js
CHANGED
|
@@ -23,9 +23,12 @@ const ONREADLINK = Symbol('onreadlink')
|
|
|
23
23
|
const OPENFILE = Symbol('openfile')
|
|
24
24
|
const ONOPENFILE = Symbol('onopenfile')
|
|
25
25
|
const CLOSE = Symbol('close')
|
|
26
|
+
const MODE = Symbol('mode')
|
|
26
27
|
const warner = require('./warn-mixin.js')
|
|
27
28
|
const winchars = require('./winchars.js')
|
|
28
29
|
|
|
30
|
+
const modeFix = require('./mode-fix.js')
|
|
31
|
+
|
|
29
32
|
const WriteEntry = warner(class WriteEntry extends MiniPass {
|
|
30
33
|
constructor (p, opt) {
|
|
31
34
|
opt = opt || {}
|
|
@@ -104,6 +107,10 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
|
|
|
104
107
|
}
|
|
105
108
|
}
|
|
106
109
|
|
|
110
|
+
[MODE] (mode) {
|
|
111
|
+
return modeFix(mode, this.type === 'Directory')
|
|
112
|
+
}
|
|
113
|
+
|
|
107
114
|
[HEADER] () {
|
|
108
115
|
if (this.type === 'Directory' && this.portable)
|
|
109
116
|
this.noMtime = true
|
|
@@ -113,7 +120,7 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
|
|
|
113
120
|
linkpath: this.linkpath,
|
|
114
121
|
// only the permissions and setuid/setgid/sticky bitflags
|
|
115
122
|
// not the higher-order bits that specify file type
|
|
116
|
-
mode: this.stat.mode
|
|
123
|
+
mode: this[MODE](this.stat.mode),
|
|
117
124
|
uid: this.portable ? null : this.stat.uid,
|
|
118
125
|
gid: this.portable ? null : this.stat.gid,
|
|
119
126
|
size: this.stat.size,
|
|
@@ -312,9 +319,7 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
|
|
|
312
319
|
this.noMtime = true
|
|
313
320
|
|
|
314
321
|
this.path = readEntry.path
|
|
315
|
-
this.mode = readEntry.mode
|
|
316
|
-
if (this.mode)
|
|
317
|
-
this.mode = this.mode & 0o7777
|
|
322
|
+
this.mode = this[MODE](readEntry.mode)
|
|
318
323
|
this.uid = this.portable ? null : readEntry.uid
|
|
319
324
|
this.gid = this.portable ? null : readEntry.gid
|
|
320
325
|
this.uname = this.portable ? null : readEntry.uname
|
|
@@ -376,6 +381,10 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
|
|
|
376
381
|
readEntry.pipe(this)
|
|
377
382
|
}
|
|
378
383
|
|
|
384
|
+
[MODE] (mode) {
|
|
385
|
+
return modeFix(mode, this.type === 'Directory')
|
|
386
|
+
}
|
|
387
|
+
|
|
379
388
|
write (data) {
|
|
380
389
|
const writeLen = data.length
|
|
381
390
|
if (writeLen > this.blockRemain)
|
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.4.
|
|
5
|
+
"version": "4.4.6",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/npm/node-tar.git"
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"chownr": "^1.0.1",
|
|
20
20
|
"fs-minipass": "^1.2.5",
|
|
21
|
-
"minipass": "^2.
|
|
21
|
+
"minipass": "^2.3.3",
|
|
22
22
|
"minizlib": "^1.1.0",
|
|
23
23
|
"mkdirp": "^0.5.0",
|
|
24
24
|
"safe-buffer": "^5.1.2",
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
"events-to-array": "^1.1.2",
|
|
31
31
|
"mutate-fs": "^2.1.1",
|
|
32
32
|
"rimraf": "^2.6.2",
|
|
33
|
-
"tap": "^
|
|
33
|
+
"tap": "^12.0.1",
|
|
34
34
|
"tar-fs": "^1.16.2",
|
|
35
35
|
"tar-stream": "^1.6.0"
|
|
36
36
|
},
|