tar 6.1.0 → 6.1.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/lib/extract.js +4 -3
- package/lib/list.js +4 -3
- package/lib/strip-absolute-path.js +14 -0
- package/lib/strip-trailing-slashes.js +24 -0
- package/lib/unpack.js +29 -5
- package/lib/write-entry.js +13 -10
- package/package.json +2 -2
- package/CHANGELOG.md +0 -68
package/lib/extract.js
CHANGED
|
@@ -6,6 +6,7 @@ const Unpack = require('./unpack.js')
|
|
|
6
6
|
const fs = require('fs')
|
|
7
7
|
const fsm = require('fs-minipass')
|
|
8
8
|
const path = require('path')
|
|
9
|
+
const stripSlash = require('./strip-trailing-slashes.js')
|
|
9
10
|
|
|
10
11
|
module.exports = (opt_, files, cb) => {
|
|
11
12
|
if (typeof opt_ === 'function')
|
|
@@ -41,7 +42,7 @@ module.exports = (opt_, files, cb) => {
|
|
|
41
42
|
// construct a filter that limits the file entries listed
|
|
42
43
|
// include child entries if a dir is included
|
|
43
44
|
const filesFilter = (opt, files) => {
|
|
44
|
-
const map = new Map(files.map(f => [f
|
|
45
|
+
const map = new Map(files.map(f => [stripSlash(f), true]))
|
|
45
46
|
const filter = opt.filter
|
|
46
47
|
|
|
47
48
|
const mapHas = (file, r) => {
|
|
@@ -55,8 +56,8 @@ const filesFilter = (opt, files) => {
|
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
opt.filter = filter
|
|
58
|
-
? (file, entry) => filter(file, entry) && mapHas(file
|
|
59
|
-
: file => mapHas(file
|
|
59
|
+
? (file, entry) => filter(file, entry) && mapHas(stripSlash(file))
|
|
60
|
+
: file => mapHas(stripSlash(file))
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
const extractFileSync = opt => {
|
package/lib/list.js
CHANGED
|
@@ -9,6 +9,7 @@ const Parser = require('./parse.js')
|
|
|
9
9
|
const fs = require('fs')
|
|
10
10
|
const fsm = require('fs-minipass')
|
|
11
11
|
const path = require('path')
|
|
12
|
+
const stripSlash = require('./strip-trailing-slashes.js')
|
|
12
13
|
|
|
13
14
|
module.exports = (opt_, files, cb) => {
|
|
14
15
|
if (typeof opt_ === 'function')
|
|
@@ -54,7 +55,7 @@ const onentryFunction = opt => {
|
|
|
54
55
|
// construct a filter that limits the file entries listed
|
|
55
56
|
// include child entries if a dir is included
|
|
56
57
|
const filesFilter = (opt, files) => {
|
|
57
|
-
const map = new Map(files.map(f => [f
|
|
58
|
+
const map = new Map(files.map(f => [stripSlash(f), true]))
|
|
58
59
|
const filter = opt.filter
|
|
59
60
|
|
|
60
61
|
const mapHas = (file, r) => {
|
|
@@ -68,8 +69,8 @@ const filesFilter = (opt, files) => {
|
|
|
68
69
|
}
|
|
69
70
|
|
|
70
71
|
opt.filter = filter
|
|
71
|
-
? (file, entry) => filter(file, entry) && mapHas(file
|
|
72
|
-
: file => mapHas(file
|
|
72
|
+
? (file, entry) => filter(file, entry) && mapHas(stripSlash(file))
|
|
73
|
+
: file => mapHas(stripSlash(file))
|
|
73
74
|
}
|
|
74
75
|
|
|
75
76
|
const listFileSync = opt => {
|
|
@@ -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
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
// this is the only approach that was significantly faster than using
|
|
2
|
+
// str.replace(/\/+$/, '') for strings ending with a lot of / chars and
|
|
3
|
+
// containing multiple / chars.
|
|
4
|
+
const batchStrings = [
|
|
5
|
+
'/'.repeat(1024),
|
|
6
|
+
'/'.repeat(512),
|
|
7
|
+
'/'.repeat(256),
|
|
8
|
+
'/'.repeat(128),
|
|
9
|
+
'/'.repeat(64),
|
|
10
|
+
'/'.repeat(32),
|
|
11
|
+
'/'.repeat(16),
|
|
12
|
+
'/'.repeat(8),
|
|
13
|
+
'/'.repeat(4),
|
|
14
|
+
'/'.repeat(2),
|
|
15
|
+
'/',
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
module.exports = str => {
|
|
19
|
+
for (const s of batchStrings) {
|
|
20
|
+
while (str.length >= s.length && str.slice(-1 * s.length) === s)
|
|
21
|
+
str = str.slice(0, -1 * s.length)
|
|
22
|
+
}
|
|
23
|
+
return str
|
|
24
|
+
}
|
package/lib/unpack.js
CHANGED
|
@@ -14,6 +14,7 @@ const path = require('path')
|
|
|
14
14
|
const mkdir = require('./mkdir.js')
|
|
15
15
|
const wc = require('./winchars.js')
|
|
16
16
|
const pathReservations = require('./path-reservations.js')
|
|
17
|
+
const stripAbsolutePath = require('./strip-absolute-path.js')
|
|
17
18
|
|
|
18
19
|
const ONENTRY = Symbol('onEntry')
|
|
19
20
|
const CHECKFS = Symbol('checkFs')
|
|
@@ -204,6 +205,8 @@ class Unpack extends Parser {
|
|
|
204
205
|
if (parts.length < this.strip)
|
|
205
206
|
return false
|
|
206
207
|
entry.path = parts.slice(this.strip).join('/')
|
|
208
|
+
if (entry.path === '' && entry.type !== 'Directory' && entry.type !== 'GNUDumpDir')
|
|
209
|
+
return false
|
|
207
210
|
|
|
208
211
|
if (entry.type === 'Link') {
|
|
209
212
|
const linkparts = entry.linkpath.split(/\/|\\/)
|
|
@@ -224,11 +227,10 @@ class Unpack extends Parser {
|
|
|
224
227
|
|
|
225
228
|
// absolutes on posix are also absolutes on win32
|
|
226
229
|
// so we only need to test this one to get both
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
entry.path =
|
|
230
|
-
|
|
231
|
-
this.warn('TAR_ENTRY_INFO', `stripping ${r} from absolute path`, {
|
|
230
|
+
const [root, stripped] = stripAbsolutePath(p)
|
|
231
|
+
if (root) {
|
|
232
|
+
entry.path = stripped
|
|
233
|
+
this.warn('TAR_ENTRY_INFO', `stripping ${root} from absolute path`, {
|
|
232
234
|
entry,
|
|
233
235
|
path: p,
|
|
234
236
|
})
|
|
@@ -465,6 +467,19 @@ class Unpack extends Parser {
|
|
|
465
467
|
}
|
|
466
468
|
|
|
467
469
|
[CHECKFS2] (entry, done) {
|
|
470
|
+
// if we are not creating a directory, and the path is in the dirCache,
|
|
471
|
+
// then that means we are about to delete the directory we created
|
|
472
|
+
// previously, and it is no longer going to be a directory, and neither
|
|
473
|
+
// is any of its children.
|
|
474
|
+
if (entry.type !== 'Directory') {
|
|
475
|
+
for (const path of this.dirCache.keys()) {
|
|
476
|
+
if (path === entry.absolute ||
|
|
477
|
+
path.indexOf(entry.absolute + '/') === 0 ||
|
|
478
|
+
path.indexOf(entry.absolute + '\\') === 0)
|
|
479
|
+
this.dirCache.delete(path)
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
|
|
468
483
|
this[MKDIR](path.dirname(entry.absolute), this.dmode, er => {
|
|
469
484
|
if (er) {
|
|
470
485
|
done()
|
|
@@ -529,6 +544,15 @@ class Unpack extends Parser {
|
|
|
529
544
|
|
|
530
545
|
class UnpackSync extends Unpack {
|
|
531
546
|
[CHECKFS] (entry) {
|
|
547
|
+
if (entry.type !== 'Directory') {
|
|
548
|
+
for (const path of this.dirCache.keys()) {
|
|
549
|
+
if (path === entry.absolute ||
|
|
550
|
+
path.indexOf(entry.absolute + '/') === 0 ||
|
|
551
|
+
path.indexOf(entry.absolute + '\\') === 0)
|
|
552
|
+
this.dirCache.delete(path)
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
|
|
532
556
|
const er = this[MKDIR](path.dirname(entry.absolute), this.dmode, neverCalled)
|
|
533
557
|
if (er)
|
|
534
558
|
return this[ONERROR](er, entry)
|
package/lib/write-entry.js
CHANGED
|
@@ -23,6 +23,7 @@ const CLOSE = Symbol('close')
|
|
|
23
23
|
const MODE = Symbol('mode')
|
|
24
24
|
const warner = require('./warn-mixin.js')
|
|
25
25
|
const winchars = require('./winchars.js')
|
|
26
|
+
const stripAbsolutePath = require('./strip-absolute-path.js')
|
|
26
27
|
|
|
27
28
|
const modeFix = require('./mode-fix.js')
|
|
28
29
|
|
|
@@ -52,12 +53,12 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
|
|
|
52
53
|
this.on('warn', opt.onwarn)
|
|
53
54
|
|
|
54
55
|
let pathWarn = false
|
|
55
|
-
if (!this.preservePaths
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
if (!this.preservePaths) {
|
|
57
|
+
const [root, stripped] = stripAbsolutePath(this.path)
|
|
58
|
+
if (root) {
|
|
59
|
+
this.path = stripped
|
|
60
|
+
pathWarn = root
|
|
61
|
+
}
|
|
61
62
|
}
|
|
62
63
|
|
|
63
64
|
this.win32 = !!opt.win32 || process.platform === 'win32'
|
|
@@ -351,10 +352,12 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
|
|
|
351
352
|
this.on('warn', opt.onwarn)
|
|
352
353
|
|
|
353
354
|
let pathWarn = false
|
|
354
|
-
if (
|
|
355
|
-
const
|
|
356
|
-
|
|
357
|
-
|
|
355
|
+
if (!this.preservePaths) {
|
|
356
|
+
const [root, stripped] = stripAbsolutePath(this.path)
|
|
357
|
+
if (root) {
|
|
358
|
+
this.path = stripped
|
|
359
|
+
pathWarn = root
|
|
360
|
+
}
|
|
358
361
|
}
|
|
359
362
|
|
|
360
363
|
this.remain = readEntry.size
|
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": "6.1.
|
|
5
|
+
"version": "6.1.4",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/npm/node-tar.git"
|
|
@@ -38,7 +38,7 @@
|
|
|
38
38
|
"events-to-array": "^1.1.2",
|
|
39
39
|
"mutate-fs": "^2.1.1",
|
|
40
40
|
"rimraf": "^2.7.1",
|
|
41
|
-
"tap": "^
|
|
41
|
+
"tap": "^15.0.9",
|
|
42
42
|
"tar-fs": "^1.16.3",
|
|
43
43
|
"tar-stream": "^1.6.2"
|
|
44
44
|
},
|
package/CHANGELOG.md
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
# Changelog
|
|
2
|
-
|
|
3
|
-
## 6.0
|
|
4
|
-
|
|
5
|
-
- Drop support for node 6 and 8
|
|
6
|
-
- fix symlinks and hardlinks on windows being packed with `\`-style path
|
|
7
|
-
targets
|
|
8
|
-
|
|
9
|
-
## 5.0
|
|
10
|
-
|
|
11
|
-
- Address unpack race conditions using path reservations
|
|
12
|
-
- Change large-numbers errors from TypeError to Error
|
|
13
|
-
- Add `TAR_*` error codes
|
|
14
|
-
- Raise `TAR_BAD_ARCHIVE` warning/error when there are no valid entries
|
|
15
|
-
found in an archive
|
|
16
|
-
- do not treat ignored entries as an invalid archive
|
|
17
|
-
- drop support for node v4
|
|
18
|
-
- unpack: conditionally use a file mapping to write files on Windows
|
|
19
|
-
- Set more portable 'mode' value in portable mode
|
|
20
|
-
- Set `portable` gzip option in portable mode
|
|
21
|
-
|
|
22
|
-
## 4.4
|
|
23
|
-
|
|
24
|
-
- Add 'mtime' option to tar creation to force mtime
|
|
25
|
-
- unpack: only reuse file fs entries if nlink = 1
|
|
26
|
-
- unpack: rename before unlinking files on Windows
|
|
27
|
-
- Fix encoding/decoding of base-256 numbers
|
|
28
|
-
- Use `stat` instead of `lstat` when checking CWD
|
|
29
|
-
- Always provide a callback to fs.close()
|
|
30
|
-
|
|
31
|
-
## 4.3
|
|
32
|
-
|
|
33
|
-
- Add 'transform' unpack option
|
|
34
|
-
|
|
35
|
-
## 4.2
|
|
36
|
-
|
|
37
|
-
- Fail when zlib fails
|
|
38
|
-
|
|
39
|
-
## 4.1
|
|
40
|
-
|
|
41
|
-
- Add noMtime flag for tar creation
|
|
42
|
-
|
|
43
|
-
## 4.0
|
|
44
|
-
|
|
45
|
-
- unpack: raise error if cwd is missing or not a dir
|
|
46
|
-
- pack: don't drop dots from dotfiles when prefixing
|
|
47
|
-
|
|
48
|
-
## 3.1
|
|
49
|
-
|
|
50
|
-
- Support `@file.tar` as an entry argument to copy entries from one tar
|
|
51
|
-
file to another.
|
|
52
|
-
- Add `noPax` option
|
|
53
|
-
- `noResume` option for tar.t
|
|
54
|
-
- win32: convert `>|<?:` chars to windows-friendly form
|
|
55
|
-
- Exclude mtime for dirs in portable mode
|
|
56
|
-
|
|
57
|
-
## 3.0
|
|
58
|
-
|
|
59
|
-
- Minipass-based implementation
|
|
60
|
-
- Entirely new API surface, `tar.c()`, `tar.x()` etc., much closer to
|
|
61
|
-
system tar semantics
|
|
62
|
-
- Massive performance improvement
|
|
63
|
-
- Require node 4.x and higher
|
|
64
|
-
|
|
65
|
-
## 0.x, 1.x, 2.x - 2011-2014
|
|
66
|
-
|
|
67
|
-
- fstream-based implementation
|
|
68
|
-
- slow and kinda bad, but better than npm shelling out to the system `tar`
|