tar 4.4.0 → 4.4.4
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 +3 -1
- package/lib/buffer.js +11 -0
- package/lib/header.js +2 -1
- package/lib/list.js +2 -0
- package/lib/mode-fix.js +14 -0
- package/lib/pack.js +3 -0
- package/lib/parse.js +1 -1
- package/lib/pax.js +1 -0
- package/lib/replace.js +1 -0
- package/lib/unpack.js +55 -4
- package/lib/write-entry.js +14 -4
- package/package.json +8 -7
package/README.md
CHANGED
|
@@ -534,7 +534,6 @@ The following options are supported:
|
|
|
534
534
|
- `mtime` Set to a `Date` object to force a specific `mtime` for
|
|
535
535
|
everything added to the archive. Overridden by `noMtime`.
|
|
536
536
|
|
|
537
|
-
|
|
538
537
|
#### add(path)
|
|
539
538
|
|
|
540
539
|
Adds an entry to the archive. Returns the Pack stream.
|
|
@@ -784,6 +783,9 @@ The following options are supported:
|
|
|
784
783
|
- `noMtime` Set to true to omit writing `mtime` values for entries.
|
|
785
784
|
Note that this prevents using other mtime-based features like
|
|
786
785
|
`tar.update` or the `keepNewer` option with the resulting tar archive.
|
|
786
|
+
- `umask` Set to restrict the modes on the entries in the archive,
|
|
787
|
+
somewhat like how umask works on file creation. Defaults to
|
|
788
|
+
`process.umask()` on unix systems, or `0o22` on Windows.
|
|
787
789
|
|
|
788
790
|
#### warn(message, data)
|
|
789
791
|
|
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,8 +4,9 @@
|
|
|
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
|
-
const pathModule = require('path')
|
|
9
|
+
const pathModule = require('path').posix
|
|
9
10
|
const large = require('./large-numbers.js')
|
|
10
11
|
|
|
11
12
|
const TYPE = Symbol('type')
|
package/lib/list.js
CHANGED
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
|
@@ -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.
|
|
@@ -69,6 +71,7 @@ const Pack = warner(class Pack extends MiniPass {
|
|
|
69
71
|
this.linkCache = opt.linkCache || new Map()
|
|
70
72
|
this.statCache = opt.statCache || new Map()
|
|
71
73
|
this.readdirCache = opt.readdirCache || new Map()
|
|
74
|
+
|
|
72
75
|
this[WRITEENTRYCLASS] = WriteEntry
|
|
73
76
|
if (typeof opt.onwarn === 'function')
|
|
74
77
|
this.on('warn', opt.onwarn)
|
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 =
|
|
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
package/lib/replace.js
CHANGED
package/lib/unpack.js
CHANGED
|
@@ -12,6 +12,7 @@ const wc = require('./winchars.js')
|
|
|
12
12
|
|
|
13
13
|
const ONENTRY = Symbol('onEntry')
|
|
14
14
|
const CHECKFS = Symbol('checkFs')
|
|
15
|
+
const ISREUSABLE = Symbol('isReusable')
|
|
15
16
|
const MAKEFS = Symbol('makeFs')
|
|
16
17
|
const FILE = Symbol('file')
|
|
17
18
|
const DIRECTORY = Symbol('directory')
|
|
@@ -32,6 +33,45 @@ const SKIP = Symbol('skip')
|
|
|
32
33
|
const DOCHOWN = Symbol('doChown')
|
|
33
34
|
const UID = Symbol('uid')
|
|
34
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
|
+
}
|
|
35
75
|
|
|
36
76
|
// this.gid, entry.gid, this.processUid
|
|
37
77
|
const uint32 = (a, b, c) =>
|
|
@@ -351,6 +391,17 @@ class Unpack extends Parser {
|
|
|
351
391
|
entry.resume()
|
|
352
392
|
}
|
|
353
393
|
|
|
394
|
+
// Check if we can reuse an existing filesystem entry safely and
|
|
395
|
+
// overwrite it, rather than unlinking and recreating
|
|
396
|
+
// Windows doesn't report a useful nlink, so we just never reuse entries
|
|
397
|
+
[ISREUSABLE] (entry, st) {
|
|
398
|
+
return entry.type === 'File' &&
|
|
399
|
+
!this.unlink &&
|
|
400
|
+
st.isFile() &&
|
|
401
|
+
st.nlink <= 1 &&
|
|
402
|
+
process.platform !== 'win32'
|
|
403
|
+
}
|
|
404
|
+
|
|
354
405
|
// check if a thing is there, and if so, try to clobber it
|
|
355
406
|
[CHECKFS] (entry) {
|
|
356
407
|
this[PEND]()
|
|
@@ -360,7 +411,7 @@ class Unpack extends Parser {
|
|
|
360
411
|
fs.lstat(entry.absolute, (er, st) => {
|
|
361
412
|
if (st && (this.keep || this.newer && st.mtime > entry.mtime))
|
|
362
413
|
this[SKIP](entry)
|
|
363
|
-
else if (er || (entry
|
|
414
|
+
else if (er || this[ISREUSABLE](entry, st))
|
|
364
415
|
this[MAKEFS](null, entry)
|
|
365
416
|
else if (st.isDirectory()) {
|
|
366
417
|
if (entry.type === 'Directory') {
|
|
@@ -371,7 +422,7 @@ class Unpack extends Parser {
|
|
|
371
422
|
} else
|
|
372
423
|
fs.rmdir(entry.absolute, er => this[MAKEFS](er, entry))
|
|
373
424
|
} else
|
|
374
|
-
|
|
425
|
+
unlinkFile(entry.absolute, er => this[MAKEFS](er, entry))
|
|
375
426
|
})
|
|
376
427
|
})
|
|
377
428
|
}
|
|
@@ -422,7 +473,7 @@ class UnpackSync extends Unpack {
|
|
|
422
473
|
const st = fs.lstatSync(entry.absolute)
|
|
423
474
|
if (this.keep || this.newer && st.mtime > entry.mtime)
|
|
424
475
|
return this[SKIP](entry)
|
|
425
|
-
else if (entry
|
|
476
|
+
else if (this[ISREUSABLE](entry, st))
|
|
426
477
|
return this[MAKEFS](null, entry)
|
|
427
478
|
else {
|
|
428
479
|
try {
|
|
@@ -433,7 +484,7 @@ class UnpackSync extends Unpack {
|
|
|
433
484
|
} else
|
|
434
485
|
fs.rmdirSync(entry.absolute)
|
|
435
486
|
} else
|
|
436
|
-
|
|
487
|
+
unlinkFileSync(entry.absolute)
|
|
437
488
|
return this[MAKEFS](null, entry)
|
|
438
489
|
} catch (er) {
|
|
439
490
|
return this[ONERROR](er, entry)
|
package/lib/write-entry.js
CHANGED
|
@@ -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')
|
|
@@ -22,9 +23,12 @@ const ONREADLINK = Symbol('onreadlink')
|
|
|
22
23
|
const OPENFILE = Symbol('openfile')
|
|
23
24
|
const ONOPENFILE = Symbol('onopenfile')
|
|
24
25
|
const CLOSE = Symbol('close')
|
|
26
|
+
const MODE = Symbol('mode')
|
|
25
27
|
const warner = require('./warn-mixin.js')
|
|
26
28
|
const winchars = require('./winchars.js')
|
|
27
29
|
|
|
30
|
+
const modeFix = require('./mode-fix.js')
|
|
31
|
+
|
|
28
32
|
const WriteEntry = warner(class WriteEntry extends MiniPass {
|
|
29
33
|
constructor (p, opt) {
|
|
30
34
|
opt = opt || {}
|
|
@@ -103,6 +107,10 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
|
|
|
103
107
|
}
|
|
104
108
|
}
|
|
105
109
|
|
|
110
|
+
[MODE] (mode) {
|
|
111
|
+
return modeFix(mode, this.type === 'Directory')
|
|
112
|
+
}
|
|
113
|
+
|
|
106
114
|
[HEADER] () {
|
|
107
115
|
if (this.type === 'Directory' && this.portable)
|
|
108
116
|
this.noMtime = true
|
|
@@ -112,7 +120,7 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
|
|
|
112
120
|
linkpath: this.linkpath,
|
|
113
121
|
// only the permissions and setuid/setgid/sticky bitflags
|
|
114
122
|
// not the higher-order bits that specify file type
|
|
115
|
-
mode: this.stat.mode
|
|
123
|
+
mode: this[MODE](this.stat.mode),
|
|
116
124
|
uid: this.portable ? null : this.stat.uid,
|
|
117
125
|
gid: this.portable ? null : this.stat.gid,
|
|
118
126
|
size: this.stat.size,
|
|
@@ -311,9 +319,7 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
|
|
|
311
319
|
this.noMtime = true
|
|
312
320
|
|
|
313
321
|
this.path = readEntry.path
|
|
314
|
-
this.mode = readEntry.mode
|
|
315
|
-
if (this.mode)
|
|
316
|
-
this.mode = this.mode & 0o7777
|
|
322
|
+
this.mode = this[MODE](readEntry.mode)
|
|
317
323
|
this.uid = this.portable ? null : readEntry.uid
|
|
318
324
|
this.gid = this.portable ? null : readEntry.gid
|
|
319
325
|
this.uname = this.portable ? null : readEntry.uname
|
|
@@ -375,6 +381,10 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
|
|
|
375
381
|
readEntry.pipe(this)
|
|
376
382
|
}
|
|
377
383
|
|
|
384
|
+
[MODE] (mode) {
|
|
385
|
+
return modeFix(mode, this.type === 'Directory')
|
|
386
|
+
}
|
|
387
|
+
|
|
378
388
|
write (data) {
|
|
379
389
|
const writeLen = data.length
|
|
380
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.4",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/npm/node-tar.git"
|
|
@@ -17,21 +17,22 @@
|
|
|
17
17
|
},
|
|
18
18
|
"dependencies": {
|
|
19
19
|
"chownr": "^1.0.1",
|
|
20
|
-
"fs-minipass": "^1.2.
|
|
21
|
-
"minipass": "^2.
|
|
20
|
+
"fs-minipass": "^1.2.5",
|
|
21
|
+
"minipass": "^2.3.3",
|
|
22
22
|
"minizlib": "^1.1.0",
|
|
23
23
|
"mkdirp": "^0.5.0",
|
|
24
|
+
"safe-buffer": "^5.1.2",
|
|
24
25
|
"yallist": "^3.0.2"
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
28
|
"chmodr": "^1.0.2",
|
|
28
|
-
"end-of-stream": "^1.4.
|
|
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": "^
|
|
33
|
-
"tar-fs": "^1.16.
|
|
34
|
-
"tar-stream": "^1.
|
|
33
|
+
"tap": "^12.0.1",
|
|
34
|
+
"tar-fs": "^1.16.2",
|
|
35
|
+
"tar-stream": "^1.6.0"
|
|
35
36
|
},
|
|
36
37
|
"license": "ISC",
|
|
37
38
|
"engines": {
|