tar 5.0.1 → 5.0.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 CHANGED
@@ -284,8 +284,9 @@ The following options are supported:
284
284
  or `false` to omit it.
285
285
  - `portable` Omit metadata that is system-specific: `ctime`, `atime`,
286
286
  `uid`, `gid`, `uname`, `gname`, `dev`, `ino`, and `nlink`. Note
287
- that `mtime` is still included, because this is necessary other
288
- time-based operations.
287
+ that `mtime` is still included, because this is necessary for other
288
+ time-based operations. Additionally, `mode` is set to a "reasonable
289
+ default" for most unix systems, based on a `umask` value of `0o22`.
289
290
  - `preservePaths` Allow absolute paths. By default, `/` is stripped
290
291
  from absolute paths. [Alias: `P`]
291
292
  - `mode` The mode to set on the created file archive
@@ -484,8 +485,9 @@ The following options are supported:
484
485
  or `false` to omit it.
485
486
  - `portable` Omit metadata that is system-specific: `ctime`, `atime`,
486
487
  `uid`, `gid`, `uname`, `gname`, `dev`, `ino`, and `nlink`. Note
487
- that `mtime` is still included, because this is necessary other
488
- time-based operations.
488
+ that `mtime` is still included, because this is necessary for other
489
+ time-based operations. Additionally, `mode` is set to a "reasonable
490
+ default" for most unix systems, based on a `umask` value of `0o22`.
489
491
  - `preservePaths` Allow absolute paths. By default, `/` is stripped
490
492
  from absolute paths. [Alias: `P`]
491
493
  - `maxReadSize` The maximum buffer size for `fs.read()` operations.
@@ -535,8 +537,9 @@ The following options are supported:
535
537
  or `false` to omit it.
536
538
  - `portable` Omit metadata that is system-specific: `ctime`, `atime`,
537
539
  `uid`, `gid`, `uname`, `gname`, `dev`, `ino`, and `nlink`. Note
538
- that `mtime` is still included, because this is necessary other
539
- time-based operations.
540
+ that `mtime` is still included, because this is necessary for other
541
+ time-based operations. Additionally, `mode` is set to a "reasonable
542
+ default" for most unix systems, based on a `umask` value of `0o22`.
540
543
  - `preservePaths` Allow absolute paths. By default, `/` is stripped
541
544
  from absolute paths. [Alias: `P`]
542
545
  - `maxReadSize` The maximum buffer size for `fs.read()` operations.
@@ -582,8 +585,9 @@ The following options are supported:
582
585
  or `false` to omit it.
583
586
  - `portable` Omit metadata that is system-specific: `ctime`, `atime`,
584
587
  `uid`, `gid`, `uname`, `gname`, `dev`, `ino`, and `nlink`. Note
585
- that `mtime` is still included, because this is necessary other
586
- time-based operations.
588
+ that `mtime` is still included, because this is necessary for other
589
+ time-based operations. Additionally, `mode` is set to a "reasonable
590
+ default" for most unix systems, based on a `umask` value of `0o22`.
587
591
  - `preservePaths` Allow absolute paths. By default, `/` is stripped
588
592
  from absolute paths.
589
593
  - `linkCache` A Map object containing the device and inode value for
@@ -795,8 +799,9 @@ It has the following fields:
795
799
  object.
796
800
  - `portable` Omit metadata that is system-specific: `ctime`, `atime`,
797
801
  `uid`, `gid`, `uname`, `gname`, `dev`, `ino`, and `nlink`. Note
798
- that `mtime` is still included, because this is necessary other
799
- time-based operations.
802
+ that `mtime` is still included, because this is necessary for other
803
+ time-based operations. Additionally, `mode` is set to a "reasonable
804
+ default" for most unix systems, based on a `umask` value of `0o22`.
800
805
  - `myuid` If supported, the uid of the user running the current
801
806
  process.
802
807
  - `myuser` The `env.USER` string if set, or `''`. Set as the entry
@@ -834,8 +839,9 @@ The following options are supported:
834
839
 
835
840
  - `portable` Omit metadata that is system-specific: `ctime`, `atime`,
836
841
  `uid`, `gid`, `uname`, `gname`, `dev`, `ino`, and `nlink`. Note
837
- that `mtime` is still included, because this is necessary other
838
- time-based operations.
842
+ that `mtime` is still included, because this is necessary for other
843
+ time-based operations. Additionally, `mode` is set to a "reasonable
844
+ default" for most unix systems, based on a `umask` value of `0o22`.
839
845
  - `maxReadSize` The maximum buffer size for `fs.read()` operations.
840
846
  Defaults to 1 MB.
841
847
  - `linkCache` A Map object containing the device and inode value for
@@ -883,8 +889,9 @@ The following options are supported:
883
889
 
884
890
  - `portable` Omit metadata that is system-specific: `ctime`, `atime`,
885
891
  `uid`, `gid`, `uname`, `gname`, `dev`, `ino`, and `nlink`. Note
886
- that `mtime` is still included, because this is necessary other
887
- time-based operations.
892
+ that `mtime` is still included, because this is necessary for other
893
+ time-based operations. Additionally, `mode` is set to a "reasonable
894
+ default" for most unix systems, based on a `umask` value of `0o22`.
888
895
  - `preservePaths` Allow absolute paths. By default, `/` is stripped
889
896
  from absolute paths.
890
897
  - `strict` Treat warnings as crash-worthy errors. Default false.
@@ -8,9 +8,13 @@
8
8
  // Only supported in Node v12.9.0 and above.
9
9
  const platform = process.env.__FAKE_PLATFORM__ || process.platform
10
10
  const isWindows = platform === 'win32'
11
- const fs = require('fs')
11
+ const fs = global.__FAKE_TESTING_FS__ || require('fs')
12
+
13
+ /* istanbul ignore next */
12
14
  const { O_CREAT, O_TRUNC, O_WRONLY, UV_FS_O_FILEMAP = 0 } = fs.constants
15
+
13
16
  const fMapEnabled = isWindows && !!UV_FS_O_FILEMAP
14
17
  const fMapLimit = 512 * 1024
15
18
  const fMapFlag = UV_FS_O_FILEMAP | O_TRUNC | O_CREAT | O_WRONLY
16
- module.exports = size => (fMapEnabled && size < fMapLimit) ? fMapFlag : 'w'
19
+ module.exports = !fMapEnabled ? () => 'w'
20
+ : size => size < fMapLimit ? fMapFlag : 'w'
package/lib/mode-fix.js CHANGED
@@ -1,6 +1,16 @@
1
1
  'use strict'
2
- module.exports = (mode, isDir) => {
2
+ module.exports = (mode, isDir, portable) => {
3
3
  mode &= 0o7777
4
+
5
+ // in portable mode, use the minimum reasonable umask
6
+ // if this system creates files with 0o664 by default
7
+ // (as some linux distros do), then we'll write the
8
+ // archive with 0o644 instead. Also, don't ever create
9
+ // a file that is not readable/writable by the owner.
10
+ if (portable) {
11
+ mode = (mode | 0o600) &~0o22
12
+ }
13
+
4
14
  // if dirs are readable, then they should be listable
5
15
  if (isDir) {
6
16
  if (mode & 0o400)
package/lib/pack.js CHANGED
@@ -75,10 +75,13 @@ const Pack = warner(class Pack extends MiniPass {
75
75
  if (typeof opt.onwarn === 'function')
76
76
  this.on('warn', opt.onwarn)
77
77
 
78
+ this.portable = !!opt.portable
78
79
  this.zip = null
79
80
  if (opt.gzip) {
80
81
  if (typeof opt.gzip !== 'object')
81
82
  opt.gzip = {}
83
+ if (this.portable)
84
+ opt.gzip.portable = true
82
85
  this.zip = new zlib.Gzip(opt.gzip)
83
86
  this.zip.on('data', chunk => super.write(chunk))
84
87
  this.zip.on('end', _ => super.end())
@@ -87,7 +90,6 @@ const Pack = warner(class Pack extends MiniPass {
87
90
  } else
88
91
  this.on('drain', this[ONDRAIN])
89
92
 
90
- this.portable = !!opt.portable
91
93
  this.noDirRecurse = !!opt.noDirRecurse
92
94
  this.follow = !!opt.follow
93
95
  this.noMtime = !!opt.noMtime
@@ -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/unpack.js CHANGED
@@ -16,6 +16,7 @@ const mkdir = require('./mkdir.js')
16
16
  const mkdirSync = mkdir.sync
17
17
  const wc = require('./winchars.js')
18
18
  const pathReservations = require('./path-reservations.js')
19
+ const stripAbsolutePath = require('./strip-absolute-path.js')
19
20
 
20
21
  const ONENTRY = Symbol('onEntry')
21
22
  const CHECKFS = Symbol('checkFs')
@@ -223,11 +224,10 @@ class Unpack extends Parser {
223
224
 
224
225
  // absolutes on posix are also absolutes on win32
225
226
  // so we only need to test this one to get both
226
- if (path.win32.isAbsolute(p)) {
227
- const parsed = path.win32.parse(p)
228
- entry.path = p.substr(parsed.root.length)
229
- const r = parsed.root
230
- this.warn('TAR_ENTRY_INFO', `stripping ${r} from absolute path`, {
227
+ const [root, stripped] = stripAbsolutePath(p)
228
+ if (root) {
229
+ entry.path = stripped
230
+ this.warn('TAR_ENTRY_INFO', `stripping ${root} from absolute path`, {
231
231
  entry,
232
232
  path: p,
233
233
  })
@@ -25,6 +25,7 @@ const CLOSE = Symbol('close')
25
25
  const MODE = Symbol('mode')
26
26
  const warner = require('./warn-mixin.js')
27
27
  const winchars = require('./winchars.js')
28
+ const stripAbsolutePath = require('./strip-absolute-path.js')
28
29
 
29
30
  const modeFix = require('./mode-fix.js')
30
31
 
@@ -54,12 +55,12 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
54
55
  this.on('warn', opt.onwarn)
55
56
 
56
57
  let pathWarn = false
57
- if (!this.preservePaths && path.win32.isAbsolute(p)) {
58
- // absolutes on posix are also absolutes on win32
59
- // so we only need to test this one to get both
60
- const parsed = path.win32.parse(p)
61
- this.path = p.substr(parsed.root.length)
62
- pathWarn = parsed.root
58
+ if (!this.preservePaths) {
59
+ const [root, stripped] = stripAbsolutePath(this.path)
60
+ if (root) {
61
+ this.path = stripped
62
+ pathWarn = root
63
+ }
63
64
  }
64
65
 
65
66
  this.win32 = !!opt.win32 || process.platform === 'win32'
@@ -115,7 +116,7 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
115
116
  }
116
117
 
117
118
  [MODE] (mode) {
118
- return modeFix(mode, this.type === 'Directory')
119
+ return modeFix(mode, this.type === 'Directory', this.portable)
119
120
  }
120
121
 
121
122
  [HEADER] () {
@@ -353,10 +354,12 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
353
354
  this.on('warn', opt.onwarn)
354
355
 
355
356
  let pathWarn = false
356
- if (path.isAbsolute(this.path) && !this.preservePaths) {
357
- const parsed = path.parse(this.path)
358
- pathWarn = parsed.root
359
- this.path = this.path.substr(parsed.root.length)
357
+ if (!this.preservePaths) {
358
+ const [root, stripped] = stripAbsolutePath(this.path)
359
+ if (root) {
360
+ this.path = stripped
361
+ pathWarn = root
362
+ }
360
363
  }
361
364
 
362
365
  this.remain = readEntry.size
@@ -406,7 +409,7 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
406
409
  }
407
410
 
408
411
  [MODE] (mode) {
409
- return modeFix(mode, this.type === 'Directory')
412
+ return modeFix(mode, this.type === 'Directory', this.portable)
410
413
  }
411
414
 
412
415
  write (data) {
package/package.json CHANGED
@@ -2,7 +2,10 @@
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": "5.0.1",
5
+ "version": "5.0.6",
6
+ "publishConfig": {
7
+ "tag": "v5-legacy"
8
+ },
6
9
  "repository": {
7
10
  "type": "git",
8
11
  "url": "https://github.com/npm/node-tar.git"
@@ -17,11 +20,11 @@
17
20
  },
18
21
  "dependencies": {
19
22
  "chownr": "^1.1.3",
20
- "fs-minipass": "^1.2.7",
21
- "minipass": "^2.9.0",
22
- "minizlib": "^1.2.2",
23
+ "fs-minipass": "^2.0.0",
24
+ "minipass": "^3.0.0",
25
+ "minizlib": "^2.1.0",
23
26
  "mkdirp": "^0.5.0",
24
- "yallist": "^3.0.3"
27
+ "yallist": "^4.0.0"
25
28
  },
26
29
  "devDependencies": {
27
30
  "chmodr": "^1.2.0",
@@ -29,17 +32,17 @@
29
32
  "events-to-array": "^1.1.2",
30
33
  "mutate-fs": "^2.1.1",
31
34
  "rimraf": "^2.7.1",
32
- "tap": "^14.6.5",
35
+ "tap": "^14.6.9",
33
36
  "tar-fs": "^1.16.3",
34
37
  "tar-stream": "^1.6.2"
35
38
  },
36
39
  "license": "ISC",
37
40
  "engines": {
38
- "node": ">=8"
41
+ "node": ">= 8"
39
42
  },
40
43
  "files": [
41
44
  "index.js",
42
- "lib/"
45
+ "lib/*.js"
43
46
  ],
44
47
  "tap": {
45
48
  "coverage-map": "map.js",