tar 6.0.4 → 6.1.2
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 +14 -3
- package/lib/create.js +9 -10
- package/lib/extract.js +7 -13
- package/lib/header.js +13 -13
- package/lib/high-level-opt.js +3 -3
- package/lib/large-numbers.js +16 -14
- package/lib/list.js +12 -9
- package/lib/mkdir.js +10 -10
- package/lib/mode-fix.js +2 -3
- package/lib/pack.js +14 -10
- package/lib/parse.js +7 -9
- package/lib/path-reservations.js +6 -6
- package/lib/pax.js +5 -7
- package/lib/read-entry.js +5 -4
- package/lib/replace.js +18 -15
- package/lib/strip-absolute-path.js +14 -0
- package/lib/types.js +1 -1
- package/lib/unpack.js +49 -27
- package/lib/update.js +1 -1
- package/lib/warn-mixin.js +2 -2
- package/lib/winchars.js +2 -2
- package/lib/write-entry.js +29 -27
- package/package.json +11 -2
- package/CHANGELOG.md +0 -68
package/lib/pax.js
CHANGED
|
@@ -34,9 +34,8 @@ class Pax {
|
|
|
34
34
|
const buf = Buffer.allocUnsafe(bufLen)
|
|
35
35
|
|
|
36
36
|
// 0-fill the header section, it might not hit every field
|
|
37
|
-
for (let i = 0; i < 512; i++)
|
|
37
|
+
for (let i = 0; i < 512; i++)
|
|
38
38
|
buf[i] = 0
|
|
39
|
-
}
|
|
40
39
|
|
|
41
40
|
new Header({
|
|
42
41
|
// XXX split the path
|
|
@@ -55,15 +54,14 @@ class Pax {
|
|
|
55
54
|
devmaj: 0,
|
|
56
55
|
devmin: 0,
|
|
57
56
|
atime: this.atime || null,
|
|
58
|
-
ctime: this.ctime || null
|
|
57
|
+
ctime: this.ctime || null,
|
|
59
58
|
}).encode(buf)
|
|
60
59
|
|
|
61
60
|
buf.write(body, 512, bodyLen, 'utf8')
|
|
62
61
|
|
|
63
62
|
// null pad after the body
|
|
64
|
-
for (let i = bodyLen + 512; i < buf.length; i++)
|
|
63
|
+
for (let i = bodyLen + 512; i < buf.length; i++)
|
|
65
64
|
buf[i] = 0
|
|
66
|
-
}
|
|
67
65
|
|
|
68
66
|
return buf
|
|
69
67
|
}
|
|
@@ -95,7 +93,7 @@ class Pax {
|
|
|
95
93
|
: this[field]
|
|
96
94
|
const s = ' ' +
|
|
97
95
|
(field === 'dev' || field === 'ino' || field === 'nlink'
|
|
98
|
-
|
|
96
|
+
? 'SCHILY.' : '') +
|
|
99
97
|
field + '=' + v + '\n'
|
|
100
98
|
const byteLen = Buffer.byteLength(s)
|
|
101
99
|
// the digits includes the length of the digits in ascii base-10
|
|
@@ -136,7 +134,7 @@ const parseKVLine = (set, line) => {
|
|
|
136
134
|
|
|
137
135
|
const v = kv.join('=')
|
|
138
136
|
set[k] = /^([A-Z]+\.)?([mac]|birth|creation)time$/.test(k)
|
|
139
|
-
?
|
|
137
|
+
? new Date(v * 1000)
|
|
140
138
|
: /^[0-9]+$/.test(v) ? +v
|
|
141
139
|
: v
|
|
142
140
|
return set
|
package/lib/read-entry.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
-
const types = require('./types.js')
|
|
3
2
|
const MiniPass = require('minipass')
|
|
4
3
|
|
|
5
4
|
const SLURP = Symbol('slurp')
|
|
@@ -63,8 +62,10 @@ module.exports = class ReadEntry extends MiniPass {
|
|
|
63
62
|
this.uname = header.uname
|
|
64
63
|
this.gname = header.gname
|
|
65
64
|
|
|
66
|
-
if (ex)
|
|
67
|
-
|
|
65
|
+
if (ex)
|
|
66
|
+
this[SLURP](ex)
|
|
67
|
+
if (gex)
|
|
68
|
+
this[SLURP](gex, true)
|
|
68
69
|
}
|
|
69
70
|
|
|
70
71
|
write (data) {
|
|
@@ -87,7 +88,7 @@ module.exports = class ReadEntry extends MiniPass {
|
|
|
87
88
|
}
|
|
88
89
|
|
|
89
90
|
[SLURP] (ex, global) {
|
|
90
|
-
for (
|
|
91
|
+
for (const k in ex) {
|
|
91
92
|
// we slurp in everything except for the path attribute in
|
|
92
93
|
// a global extended header, because that's weird.
|
|
93
94
|
if (ex[k] !== null && ex[k] !== undefined &&
|
package/lib/replace.js
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
// tar -r
|
|
4
4
|
const hlo = require('./high-level-opt.js')
|
|
5
5
|
const Pack = require('./pack.js')
|
|
6
|
-
const Parse = require('./parse.js')
|
|
7
6
|
const fs = require('fs')
|
|
8
7
|
const fsm = require('fs-minipass')
|
|
9
8
|
const t = require('./list.js')
|
|
@@ -17,7 +16,7 @@ const path = require('path')
|
|
|
17
16
|
|
|
18
17
|
const Header = require('./header.js')
|
|
19
18
|
|
|
20
|
-
|
|
19
|
+
module.exports = (opt_, files, cb) => {
|
|
21
20
|
const opt = hlo(opt_)
|
|
22
21
|
|
|
23
22
|
if (!opt.file)
|
|
@@ -68,10 +67,10 @@ const replaceSync = (opt, files) => {
|
|
|
68
67
|
break POSITION
|
|
69
68
|
}
|
|
70
69
|
|
|
71
|
-
|
|
70
|
+
const h = new Header(headBuf)
|
|
72
71
|
if (!h.cksumValid)
|
|
73
72
|
break
|
|
74
|
-
|
|
73
|
+
const entryBlockSize = 512 * Math.ceil(h.size / 512)
|
|
75
74
|
if (position + entryBlockSize + 512 > st.size)
|
|
76
75
|
break
|
|
77
76
|
// the 512 for the header we just parsed will be added as well
|
|
@@ -84,15 +83,18 @@ const replaceSync = (opt, files) => {
|
|
|
84
83
|
|
|
85
84
|
streamSync(opt, p, position, fd, files)
|
|
86
85
|
} finally {
|
|
87
|
-
if (threw)
|
|
88
|
-
try {
|
|
86
|
+
if (threw) {
|
|
87
|
+
try {
|
|
88
|
+
fs.closeSync(fd)
|
|
89
|
+
} catch (er) {}
|
|
90
|
+
}
|
|
89
91
|
}
|
|
90
92
|
}
|
|
91
93
|
|
|
92
94
|
const streamSync = (opt, p, position, fd, files) => {
|
|
93
95
|
const stream = new fsm.WriteStreamSync(opt.file, {
|
|
94
96
|
fd: fd,
|
|
95
|
-
start: position
|
|
97
|
+
start: position,
|
|
96
98
|
})
|
|
97
99
|
p.pipe(stream)
|
|
98
100
|
addFilesSync(p, files)
|
|
@@ -120,11 +122,12 @@ const replace = (opt, files, cb) => {
|
|
|
120
122
|
if (er)
|
|
121
123
|
return cb(er)
|
|
122
124
|
bufPos += bytes
|
|
123
|
-
if (bufPos < 512 && bytes)
|
|
125
|
+
if (bufPos < 512 && bytes) {
|
|
124
126
|
return fs.read(
|
|
125
127
|
fd, headBuf, bufPos, headBuf.length - bufPos,
|
|
126
128
|
position + bufPos, onread
|
|
127
129
|
)
|
|
130
|
+
}
|
|
128
131
|
|
|
129
132
|
if (position === 0 && headBuf[0] === 0x1f && headBuf[1] === 0x8b)
|
|
130
133
|
return cb(new Error('cannot append to compressed archives'))
|
|
@@ -173,7 +176,7 @@ const replace = (opt, files, cb) => {
|
|
|
173
176
|
return reject(er)
|
|
174
177
|
const stream = new fsm.WriteStream(opt.file, {
|
|
175
178
|
fd: fd,
|
|
176
|
-
start: position
|
|
179
|
+
start: position,
|
|
177
180
|
})
|
|
178
181
|
p.pipe(stream)
|
|
179
182
|
stream.on('error', reject)
|
|
@@ -190,14 +193,14 @@ const replace = (opt, files, cb) => {
|
|
|
190
193
|
|
|
191
194
|
const addFilesSync = (p, files) => {
|
|
192
195
|
files.forEach(file => {
|
|
193
|
-
if (file.charAt(0) === '@')
|
|
196
|
+
if (file.charAt(0) === '@') {
|
|
194
197
|
t({
|
|
195
198
|
file: path.resolve(p.cwd, file.substr(1)),
|
|
196
199
|
sync: true,
|
|
197
200
|
noResume: true,
|
|
198
|
-
onentry: entry => p.add(entry)
|
|
201
|
+
onentry: entry => p.add(entry),
|
|
199
202
|
})
|
|
200
|
-
else
|
|
203
|
+
} else
|
|
201
204
|
p.add(file)
|
|
202
205
|
})
|
|
203
206
|
p.end()
|
|
@@ -206,13 +209,13 @@ const addFilesSync = (p, files) => {
|
|
|
206
209
|
const addFilesAsync = (p, files) => {
|
|
207
210
|
while (files.length) {
|
|
208
211
|
const file = files.shift()
|
|
209
|
-
if (file.charAt(0) === '@')
|
|
212
|
+
if (file.charAt(0) === '@') {
|
|
210
213
|
return t({
|
|
211
214
|
file: path.resolve(p.cwd, file.substr(1)),
|
|
212
215
|
noResume: true,
|
|
213
|
-
onentry: entry => p.add(entry)
|
|
216
|
+
onentry: entry => p.add(entry),
|
|
214
217
|
}).then(_ => addFilesAsync(p, files))
|
|
215
|
-
else
|
|
218
|
+
} else
|
|
216
219
|
p.add(file)
|
|
217
220
|
}
|
|
218
221
|
p.end()
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
// unix absolute paths are also absolute on win32, so we use this for both
|
|
2
|
+
const { isAbsolute, parse } = require('path').win32
|
|
3
|
+
|
|
4
|
+
// returns [root, stripped]
|
|
5
|
+
module.exports = path => {
|
|
6
|
+
let r = ''
|
|
7
|
+
while (isAbsolute(path)) {
|
|
8
|
+
// windows will think that //x/y/z has a "root" of //x/y/
|
|
9
|
+
const root = path.charAt(0) === '/' ? '/' : parse(path).root
|
|
10
|
+
path = path.substr(root.length)
|
|
11
|
+
r += root
|
|
12
|
+
}
|
|
13
|
+
return [r, path]
|
|
14
|
+
}
|
package/lib/types.js
CHANGED
package/lib/unpack.js
CHANGED
|
@@ -7,15 +7,14 @@
|
|
|
7
7
|
// clobbering an fs object to create one of a different type.)
|
|
8
8
|
|
|
9
9
|
const assert = require('assert')
|
|
10
|
-
const EE = require('events').EventEmitter
|
|
11
10
|
const Parser = require('./parse.js')
|
|
12
11
|
const fs = require('fs')
|
|
13
12
|
const fsm = require('fs-minipass')
|
|
14
13
|
const path = require('path')
|
|
15
14
|
const mkdir = require('./mkdir.js')
|
|
16
|
-
const mkdirSync = mkdir.sync
|
|
17
15
|
const wc = require('./winchars.js')
|
|
18
16
|
const pathReservations = require('./path-reservations.js')
|
|
17
|
+
const stripAbsolutePath = require('./strip-absolute-path.js')
|
|
19
18
|
|
|
20
19
|
const ONENTRY = Symbol('onEntry')
|
|
21
20
|
const CHECKFS = Symbol('checkFs')
|
|
@@ -28,7 +27,6 @@ const LINK = Symbol('link')
|
|
|
28
27
|
const SYMLINK = Symbol('symlink')
|
|
29
28
|
const HARDLINK = Symbol('hardlink')
|
|
30
29
|
const UNSUPPORTED = Symbol('unsupported')
|
|
31
|
-
const UNKNOWN = Symbol('unknown')
|
|
32
30
|
const CHECKPATH = Symbol('checkPath')
|
|
33
31
|
const MKDIR = Symbol('mkdir')
|
|
34
32
|
const ONERROR = Symbol('onError')
|
|
@@ -121,9 +119,10 @@ class Unpack extends Parser {
|
|
|
121
119
|
// need both or neither
|
|
122
120
|
if (typeof opt.uid !== 'number' || typeof opt.gid !== 'number')
|
|
123
121
|
throw new TypeError('cannot set owner without number uid and gid')
|
|
124
|
-
if (opt.preserveOwner)
|
|
122
|
+
if (opt.preserveOwner) {
|
|
125
123
|
throw new TypeError(
|
|
126
124
|
'cannot preserve owner in archive and also set owner explicitly')
|
|
125
|
+
}
|
|
127
126
|
this.uid = opt.uid
|
|
128
127
|
this.gid = opt.gid
|
|
129
128
|
this.setOwner = true
|
|
@@ -171,11 +170,14 @@ class Unpack extends Parser {
|
|
|
171
170
|
|
|
172
171
|
this.cwd = path.resolve(opt.cwd || process.cwd())
|
|
173
172
|
this.strip = +opt.strip || 0
|
|
174
|
-
|
|
173
|
+
// if we're not chmodding, then we don't need the process umask
|
|
174
|
+
this.processUmask = opt.noChmod ? 0 : process.umask()
|
|
175
175
|
this.umask = typeof opt.umask === 'number' ? opt.umask : this.processUmask
|
|
176
|
+
|
|
176
177
|
// default mode for dirs created as parents
|
|
177
178
|
this.dmode = opt.dmode || (0o0777 & (~this.umask))
|
|
178
179
|
this.fmode = opt.fmode || (0o0666 & (~this.umask))
|
|
180
|
+
|
|
179
181
|
this.on('entry', entry => this[ONENTRY](entry))
|
|
180
182
|
}
|
|
181
183
|
|
|
@@ -223,11 +225,10 @@ class Unpack extends Parser {
|
|
|
223
225
|
|
|
224
226
|
// absolutes on posix are also absolutes on win32
|
|
225
227
|
// so we only need to test this one to get both
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
entry.path =
|
|
229
|
-
|
|
230
|
-
this.warn('TAR_ENTRY_INFO', `stripping ${r} from absolute path`, {
|
|
228
|
+
const [root, stripped] = stripAbsolutePath(p)
|
|
229
|
+
if (root) {
|
|
230
|
+
entry.path = stripped
|
|
231
|
+
this.warn('TAR_ENTRY_INFO', `stripping ${root} from absolute path`, {
|
|
231
232
|
entry,
|
|
232
233
|
path: p,
|
|
233
234
|
})
|
|
@@ -271,6 +272,7 @@ class Unpack extends Parser {
|
|
|
271
272
|
case 'CharacterDevice':
|
|
272
273
|
case 'BlockDevice':
|
|
273
274
|
case 'FIFO':
|
|
275
|
+
default:
|
|
274
276
|
return this[UNSUPPORTED](entry)
|
|
275
277
|
}
|
|
276
278
|
}
|
|
@@ -299,7 +301,8 @@ class Unpack extends Parser {
|
|
|
299
301
|
unlink: this.unlink,
|
|
300
302
|
cache: this.dirCache,
|
|
301
303
|
cwd: this.cwd,
|
|
302
|
-
mode: mode
|
|
304
|
+
mode: mode,
|
|
305
|
+
noChmod: this.noChmod,
|
|
303
306
|
}, cb)
|
|
304
307
|
}
|
|
305
308
|
|
|
@@ -308,11 +311,11 @@ class Unpack extends Parser {
|
|
|
308
311
|
// in set owner mode, chown if setting doesn't match process
|
|
309
312
|
return this.forceChown ||
|
|
310
313
|
this.preserveOwner &&
|
|
311
|
-
(
|
|
312
|
-
typeof entry.gid === 'number' && entry.gid !== this.processGid
|
|
314
|
+
(typeof entry.uid === 'number' && entry.uid !== this.processUid ||
|
|
315
|
+
typeof entry.gid === 'number' && entry.gid !== this.processGid)
|
|
313
316
|
||
|
|
314
|
-
(
|
|
315
|
-
typeof this.gid === 'number' && this.gid !== this.processGid
|
|
317
|
+
(typeof this.uid === 'number' && this.uid !== this.processUid ||
|
|
318
|
+
typeof this.gid === 'number' && this.gid !== this.processGid)
|
|
316
319
|
}
|
|
317
320
|
|
|
318
321
|
[UID] (entry) {
|
|
@@ -328,7 +331,7 @@ class Unpack extends Parser {
|
|
|
328
331
|
const stream = new fsm.WriteStream(entry.absolute, {
|
|
329
332
|
flags: getFlag(entry.size),
|
|
330
333
|
mode: mode,
|
|
331
|
-
autoClose: false
|
|
334
|
+
autoClose: false,
|
|
332
335
|
})
|
|
333
336
|
stream.on('error', er => this[ONERROR](er, entry))
|
|
334
337
|
|
|
@@ -460,7 +463,21 @@ class Unpack extends Parser {
|
|
|
460
463
|
paths.push(entry.linkpath)
|
|
461
464
|
this.reservations.reserve(paths, done => this[CHECKFS2](entry, done))
|
|
462
465
|
}
|
|
466
|
+
|
|
463
467
|
[CHECKFS2] (entry, done) {
|
|
468
|
+
// if we are not creating a directory, and the path is in the dirCache,
|
|
469
|
+
// then that means we are about to delete the directory we created
|
|
470
|
+
// previously, and it is no longer going to be a directory, and neither
|
|
471
|
+
// is any of its children.
|
|
472
|
+
if (entry.type !== 'Directory') {
|
|
473
|
+
for (const path of this.dirCache.keys()) {
|
|
474
|
+
if (path === entry.absolute ||
|
|
475
|
+
path.indexOf(entry.absolute + '/') === 0 ||
|
|
476
|
+
path.indexOf(entry.absolute + '\\') === 0)
|
|
477
|
+
this.dirCache.delete(path)
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
|
|
464
481
|
this[MKDIR](path.dirname(entry.absolute), this.dmode, er => {
|
|
465
482
|
if (er) {
|
|
466
483
|
done()
|
|
@@ -470,16 +487,17 @@ class Unpack extends Parser {
|
|
|
470
487
|
if (st && (this.keep || this.newer && st.mtime > entry.mtime)) {
|
|
471
488
|
this[SKIP](entry)
|
|
472
489
|
done()
|
|
473
|
-
} else if (er || this[ISREUSABLE](entry, st))
|
|
490
|
+
} else if (er || this[ISREUSABLE](entry, st))
|
|
474
491
|
this[MAKEFS](null, entry, done)
|
|
475
|
-
|
|
492
|
+
|
|
476
493
|
else if (st.isDirectory()) {
|
|
477
494
|
if (entry.type === 'Directory') {
|
|
478
|
-
if (!entry.mode || (st.mode & 0o7777) === entry.mode)
|
|
495
|
+
if (!this.noChmod && (!entry.mode || (st.mode & 0o7777) === entry.mode))
|
|
479
496
|
this[MAKEFS](null, entry, done)
|
|
480
|
-
else
|
|
497
|
+
else {
|
|
481
498
|
fs.chmod(entry.absolute, entry.mode,
|
|
482
499
|
er => this[MAKEFS](er, entry, done))
|
|
500
|
+
}
|
|
483
501
|
} else
|
|
484
502
|
fs.rmdir(entry.absolute, er => this[MAKEFS](er, entry, done))
|
|
485
503
|
} else
|
|
@@ -523,11 +541,16 @@ class Unpack extends Parser {
|
|
|
523
541
|
}
|
|
524
542
|
|
|
525
543
|
class UnpackSync extends Unpack {
|
|
526
|
-
constructor (opt) {
|
|
527
|
-
super(opt)
|
|
528
|
-
}
|
|
529
|
-
|
|
530
544
|
[CHECKFS] (entry) {
|
|
545
|
+
if (entry.type !== 'Directory') {
|
|
546
|
+
for (const path of this.dirCache.keys()) {
|
|
547
|
+
if (path === entry.absolute ||
|
|
548
|
+
path.indexOf(entry.absolute + '/') === 0 ||
|
|
549
|
+
path.indexOf(entry.absolute + '\\') === 0)
|
|
550
|
+
this.dirCache.delete(path)
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
|
|
531
554
|
const er = this[MKDIR](path.dirname(entry.absolute), this.dmode, neverCalled)
|
|
532
555
|
if (er)
|
|
533
556
|
return this[ONERROR](er, entry)
|
|
@@ -541,7 +564,7 @@ class UnpackSync extends Unpack {
|
|
|
541
564
|
try {
|
|
542
565
|
if (st.isDirectory()) {
|
|
543
566
|
if (entry.type === 'Directory') {
|
|
544
|
-
if (entry.mode && (st.mode & 0o7777) !== entry.mode)
|
|
567
|
+
if (!this.noChmod && entry.mode && (st.mode & 0o7777) !== entry.mode)
|
|
545
568
|
fs.chmodSync(entry.absolute, entry.mode)
|
|
546
569
|
} else
|
|
547
570
|
fs.rmdirSync(entry.absolute)
|
|
@@ -571,7 +594,6 @@ class UnpackSync extends Unpack {
|
|
|
571
594
|
this[ONERROR](er || closeError, entry)
|
|
572
595
|
}
|
|
573
596
|
|
|
574
|
-
let stream
|
|
575
597
|
let fd
|
|
576
598
|
try {
|
|
577
599
|
fd = fs.openSync(entry.absolute, getFlag(entry.size), mode)
|
|
@@ -659,7 +681,7 @@ class UnpackSync extends Unpack {
|
|
|
659
681
|
unlink: this.unlink,
|
|
660
682
|
cache: this.dirCache,
|
|
661
683
|
cwd: this.cwd,
|
|
662
|
-
mode: mode
|
|
684
|
+
mode: mode,
|
|
663
685
|
})
|
|
664
686
|
} catch (er) {
|
|
665
687
|
return er
|
package/lib/update.js
CHANGED
|
@@ -6,7 +6,7 @@ const hlo = require('./high-level-opt.js')
|
|
|
6
6
|
const r = require('./replace.js')
|
|
7
7
|
// just call tar.r with the filter and mtimeCache
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
module.exports = (opt_, files, cb) => {
|
|
10
10
|
const opt = hlo(opt_)
|
|
11
11
|
|
|
12
12
|
if (!opt.file)
|
package/lib/warn-mixin.js
CHANGED
|
@@ -13,9 +13,9 @@ module.exports = Base => class extends Base {
|
|
|
13
13
|
message = message.message
|
|
14
14
|
}
|
|
15
15
|
this.emit('warn', data.tarCode, message, data)
|
|
16
|
-
} else if (message instanceof Error)
|
|
16
|
+
} else if (message instanceof Error)
|
|
17
17
|
this.emit('error', Object.assign(message, data))
|
|
18
|
-
|
|
18
|
+
else
|
|
19
19
|
this.emit('error', Object.assign(new Error(`${code}: ${message}`), data))
|
|
20
20
|
}
|
|
21
21
|
}
|
package/lib/winchars.js
CHANGED
|
@@ -8,7 +8,7 @@ const raw = [
|
|
|
8
8
|
'<',
|
|
9
9
|
'>',
|
|
10
10
|
'?',
|
|
11
|
-
':'
|
|
11
|
+
':',
|
|
12
12
|
]
|
|
13
13
|
|
|
14
14
|
const win = raw.map(char =>
|
|
@@ -19,5 +19,5 @@ const toRaw = new Map(win.map((char, i) => [char, raw[i]]))
|
|
|
19
19
|
|
|
20
20
|
module.exports = {
|
|
21
21
|
encode: s => raw.reduce((s, c) => s.split(c).join(toWin.get(c)), s),
|
|
22
|
-
decode: s => win.reduce((s, c) => s.split(c).join(toRaw.get(c)), s)
|
|
22
|
+
decode: s => win.reduce((s, c) => s.split(c).join(toRaw.get(c)), s),
|
|
23
23
|
}
|
package/lib/write-entry.js
CHANGED
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
const MiniPass = require('minipass')
|
|
3
3
|
const Pax = require('./pax.js')
|
|
4
4
|
const Header = require('./header.js')
|
|
5
|
-
const ReadEntry = require('./read-entry.js')
|
|
6
5
|
const fs = require('fs')
|
|
7
6
|
const path = require('path')
|
|
8
7
|
|
|
9
|
-
const types = require('./types.js')
|
|
10
8
|
const maxReadSize = 16 * 1024 * 1024
|
|
11
9
|
const PROCESS = Symbol('process')
|
|
12
10
|
const FILE = Symbol('file')
|
|
@@ -25,6 +23,7 @@ const CLOSE = Symbol('close')
|
|
|
25
23
|
const MODE = Symbol('mode')
|
|
26
24
|
const warner = require('./warn-mixin.js')
|
|
27
25
|
const winchars = require('./winchars.js')
|
|
26
|
+
const stripAbsolutePath = require('./strip-absolute-path.js')
|
|
28
27
|
|
|
29
28
|
const modeFix = require('./mode-fix.js')
|
|
30
29
|
|
|
@@ -54,12 +53,12 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
|
|
|
54
53
|
this.on('warn', opt.onwarn)
|
|
55
54
|
|
|
56
55
|
let pathWarn = false
|
|
57
|
-
if (!this.preservePaths
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
56
|
+
if (!this.preservePaths) {
|
|
57
|
+
const [root, stripped] = stripAbsolutePath(this.path)
|
|
58
|
+
if (root) {
|
|
59
|
+
this.path = stripped
|
|
60
|
+
pathWarn = root
|
|
61
|
+
}
|
|
63
62
|
}
|
|
64
63
|
|
|
65
64
|
this.win32 = !!opt.win32 || process.platform === 'win32'
|
|
@@ -134,12 +133,12 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
|
|
|
134
133
|
mtime: this.noMtime ? null : this.mtime || this.stat.mtime,
|
|
135
134
|
type: this.type,
|
|
136
135
|
uname: this.portable ? null :
|
|
137
|
-
|
|
136
|
+
this.stat.uid === this.myuid ? this.myuser : '',
|
|
138
137
|
atime: this.portable ? null : this.stat.atime,
|
|
139
|
-
ctime: this.portable ? null : this.stat.ctime
|
|
138
|
+
ctime: this.portable ? null : this.stat.ctime,
|
|
140
139
|
})
|
|
141
140
|
|
|
142
|
-
if (this.header.encode() && !this.noPax)
|
|
141
|
+
if (this.header.encode() && !this.noPax) {
|
|
143
142
|
this.write(new Pax({
|
|
144
143
|
atime: this.portable ? null : this.header.atime,
|
|
145
144
|
ctime: this.portable ? null : this.header.ctime,
|
|
@@ -152,8 +151,9 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
|
|
|
152
151
|
uname: this.portable ? null : this.header.uname,
|
|
153
152
|
dev: this.portable ? null : this.stat.dev,
|
|
154
153
|
ino: this.portable ? null : this.stat.ino,
|
|
155
|
-
nlink: this.portable ? null : this.stat.nlink
|
|
154
|
+
nlink: this.portable ? null : this.stat.nlink,
|
|
156
155
|
}).encode())
|
|
156
|
+
}
|
|
157
157
|
this.write(this.header.block)
|
|
158
158
|
}
|
|
159
159
|
|
|
@@ -256,8 +256,8 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
|
|
|
256
256
|
if (bytesRead === remain) {
|
|
257
257
|
for (let i = bytesRead; i < length && bytesRead < blockRemain; i++) {
|
|
258
258
|
buf[i + offset] = 0
|
|
259
|
-
bytesRead
|
|
260
|
-
remain
|
|
259
|
+
bytesRead++
|
|
260
|
+
remain++
|
|
261
261
|
}
|
|
262
262
|
}
|
|
263
263
|
|
|
@@ -286,10 +286,6 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
|
|
|
286
286
|
})
|
|
287
287
|
|
|
288
288
|
class WriteEntrySync extends WriteEntry {
|
|
289
|
-
constructor (path, opt) {
|
|
290
|
-
super(path, opt)
|
|
291
|
-
}
|
|
292
|
-
|
|
293
289
|
[LSTAT] () {
|
|
294
290
|
this[ONLSTAT](fs.lstatSync(this.absolute))
|
|
295
291
|
}
|
|
@@ -311,8 +307,11 @@ class WriteEntrySync extends WriteEntry {
|
|
|
311
307
|
} finally {
|
|
312
308
|
// ignoring the error from close(2) is a bad practice, but at
|
|
313
309
|
// this point we already have an error, don't need another one
|
|
314
|
-
if (threw)
|
|
315
|
-
try {
|
|
310
|
+
if (threw) {
|
|
311
|
+
try {
|
|
312
|
+
this[CLOSE](fd, () => {})
|
|
313
|
+
} catch (er) {}
|
|
314
|
+
}
|
|
316
315
|
}
|
|
317
316
|
}
|
|
318
317
|
|
|
@@ -353,10 +352,12 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
|
|
|
353
352
|
this.on('warn', opt.onwarn)
|
|
354
353
|
|
|
355
354
|
let pathWarn = false
|
|
356
|
-
if (
|
|
357
|
-
const
|
|
358
|
-
|
|
359
|
-
|
|
355
|
+
if (!this.preservePaths) {
|
|
356
|
+
const [root, stripped] = stripAbsolutePath(this.path)
|
|
357
|
+
if (root) {
|
|
358
|
+
this.path = stripped
|
|
359
|
+
pathWarn = root
|
|
360
|
+
}
|
|
360
361
|
}
|
|
361
362
|
|
|
362
363
|
this.remain = readEntry.size
|
|
@@ -375,7 +376,7 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
|
|
|
375
376
|
type: this.type,
|
|
376
377
|
uname: this.portable ? null : this.uname,
|
|
377
378
|
atime: this.portable ? null : this.atime,
|
|
378
|
-
ctime: this.portable ? null : this.ctime
|
|
379
|
+
ctime: this.portable ? null : this.ctime,
|
|
379
380
|
})
|
|
380
381
|
|
|
381
382
|
if (pathWarn) {
|
|
@@ -385,7 +386,7 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
|
|
|
385
386
|
})
|
|
386
387
|
}
|
|
387
388
|
|
|
388
|
-
if (this.header.encode() && !this.noPax)
|
|
389
|
+
if (this.header.encode() && !this.noPax) {
|
|
389
390
|
super.write(new Pax({
|
|
390
391
|
atime: this.portable ? null : this.atime,
|
|
391
392
|
ctime: this.portable ? null : this.ctime,
|
|
@@ -398,8 +399,9 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
|
|
|
398
399
|
uname: this.portable ? null : this.uname,
|
|
399
400
|
dev: this.portable ? null : this.readEntry.dev,
|
|
400
401
|
ino: this.portable ? null : this.readEntry.ino,
|
|
401
|
-
nlink: this.portable ? null : this.readEntry.nlink
|
|
402
|
+
nlink: this.portable ? null : this.readEntry.nlink,
|
|
402
403
|
}).encode())
|
|
404
|
+
}
|
|
403
405
|
|
|
404
406
|
super.write(this.header.block)
|
|
405
407
|
readEntry.pipe(this)
|
package/package.json
CHANGED
|
@@ -2,13 +2,17 @@
|
|
|
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": "6.
|
|
5
|
+
"version": "6.1.2",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/npm/node-tar.git"
|
|
9
9
|
},
|
|
10
10
|
"scripts": {
|
|
11
11
|
"test": "tap",
|
|
12
|
+
"posttest": "npm run lint",
|
|
13
|
+
"eslint": "eslint",
|
|
14
|
+
"lint": "npm run eslint -- test lib",
|
|
15
|
+
"lintfix": "npm run lint -- --fix",
|
|
12
16
|
"preversion": "npm test",
|
|
13
17
|
"postversion": "npm publish",
|
|
14
18
|
"prepublishOnly": "git push origin --follow-tags",
|
|
@@ -26,10 +30,15 @@
|
|
|
26
30
|
"devDependencies": {
|
|
27
31
|
"chmodr": "^1.2.0",
|
|
28
32
|
"end-of-stream": "^1.4.3",
|
|
33
|
+
"eslint": "^7.17.0",
|
|
34
|
+
"eslint-plugin-import": "^2.22.1",
|
|
35
|
+
"eslint-plugin-node": "^11.1.0",
|
|
36
|
+
"eslint-plugin-promise": "^4.2.1",
|
|
37
|
+
"eslint-plugin-standard": "^5.0.0",
|
|
29
38
|
"events-to-array": "^1.1.2",
|
|
30
39
|
"mutate-fs": "^2.1.1",
|
|
31
40
|
"rimraf": "^2.7.1",
|
|
32
|
-
"tap": "^
|
|
41
|
+
"tap": "^15.0.9",
|
|
33
42
|
"tar-fs": "^1.16.3",
|
|
34
43
|
"tar-stream": "^1.6.2"
|
|
35
44
|
},
|