tar 3.2.1 → 3.2.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.
@@ -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
@@ -8,6 +8,7 @@ const path = require('path')
8
8
  const mkdir = require('./mkdir.js')
9
9
  const mkdirSync = mkdir.sync
10
10
  const wc = require('./winchars.js')
11
+ const stripAbsolutePath = require('./strip-absolute-path.js')
11
12
 
12
13
  const ONENTRY = Symbol('onEntry')
13
14
  const CHECKFS = Symbol('checkFs')
@@ -136,10 +137,10 @@ class Unpack extends Parser {
136
137
 
137
138
  // absolutes on posix are also absolutes on win32
138
139
  // so we only need to test this one to get both
139
- if (path.win32.isAbsolute(p)) {
140
- const parsed = path.win32.parse(p)
141
- this.warn('stripping ' + parsed.root + ' from absolute path', p)
142
- entry.path = p.substr(parsed.root.length)
140
+ const s = stripAbsolutePath(p)
141
+ if (s[0]) {
142
+ entry.path = s[1]
143
+ this.warn(`stripping ${s[0]} from absolute path`, p)
143
144
  }
144
145
  }
145
146
 
@@ -24,6 +24,7 @@ const ONOPENFILE = Symbol('onopenfile')
24
24
  const CLOSE = Symbol('close')
25
25
  const warner = require('./warn-mixin.js')
26
26
  const winchars = require('./winchars.js')
27
+ const stripAbsolutePath = require('./strip-absolute-path.js')
27
28
 
28
29
  const WriteEntry = warner(class WriteEntry extends MiniPass {
29
30
  constructor (p, opt) {
@@ -47,12 +48,12 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
47
48
  if (typeof opt.onwarn === 'function')
48
49
  this.on('warn', opt.onwarn)
49
50
 
50
- if (!this.preservePaths && path.win32.isAbsolute(p)) {
51
- // absolutes on posix are also absolutes on win32
52
- // so we only need to test this one to get both
53
- const parsed = path.win32.parse(p)
54
- this.warn('stripping ' + parsed.root + ' from absolute path', p)
55
- this.path = p.substr(parsed.root.length)
51
+ if (!this.preservePaths) {
52
+ const s = stripAbsolutePath(this.path)
53
+ if (s[0]) {
54
+ this.path = s[1]
55
+ this.warn('stripping ' + s[0] + ' from absolute path', p)
56
+ }
56
57
  }
57
58
 
58
59
  this.win32 = !!opt.win32 || process.platform === 'win32'
@@ -320,13 +321,15 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
320
321
  if (typeof opt.onwarn === 'function')
321
322
  this.on('warn', opt.onwarn)
322
323
 
323
- if (path.isAbsolute(this.path) && !this.preservePaths) {
324
- const parsed = path.parse(this.path)
325
- this.warn(
326
- 'stripping ' + parsed.root + ' from absolute path',
327
- this.path
328
- )
329
- this.path = this.path.substr(parsed.root.length)
324
+ if (!this.preservePaths) {
325
+ const s = stripAbsolutePath(this.path)
326
+ if (s[0]) {
327
+ this.warn(
328
+ 'stripping ' + s[0] + ' from absolute path',
329
+ this.path
330
+ )
331
+ this.path = s[1]
332
+ }
330
333
  }
331
334
 
332
335
  this.remain = readEntry.size
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": "3.2.1",
5
+ "version": "3.2.2",
6
+ "publishConfig": {
7
+ "tag": "v3-legacy"
8
+ },
6
9
  "repository": {
7
10
  "type": "git",
8
11
  "url": "https://github.com/npm/node-tar.git"