tar 5.0.10 → 6.0.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/CHANGELOG.md ADDED
@@ -0,0 +1,68 @@
1
+ # Charge Long
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`
package/lib/extract.js CHANGED
@@ -6,7 +6,6 @@ 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')
10
9
 
11
10
  const x = module.exports = (opt_, files, cb) => {
12
11
  if (typeof opt_ === 'function')
@@ -42,7 +41,7 @@ const x = module.exports = (opt_, files, cb) => {
42
41
  // construct a filter that limits the file entries listed
43
42
  // include child entries if a dir is included
44
43
  const filesFilter = (opt, files) => {
45
- const map = new Map(files.map(f => [stripSlash(f), true]))
44
+ const map = new Map(files.map(f => [f.replace(/\/+$/, ''), true]))
46
45
  const filter = opt.filter
47
46
 
48
47
  const mapHas = (file, r) => {
@@ -56,8 +55,8 @@ const filesFilter = (opt, files) => {
56
55
  }
57
56
 
58
57
  opt.filter = filter
59
- ? (file, entry) => filter(file, entry) && mapHas(stripSlash(file))
60
- : file => mapHas(stripSlash(file))
58
+ ? (file, entry) => filter(file, entry) && mapHas(file.replace(/\/+$/, ''))
59
+ : file => mapHas(file.replace(/\/+$/, ''))
61
60
  }
62
61
 
63
62
  const extractFileSync = opt => {
package/lib/list.js CHANGED
@@ -9,7 +9,6 @@ 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')
13
12
 
14
13
  const t = module.exports = (opt_, files, cb) => {
15
14
  if (typeof opt_ === 'function')
@@ -55,7 +54,7 @@ const onentryFunction = opt => {
55
54
  // construct a filter that limits the file entries listed
56
55
  // include child entries if a dir is included
57
56
  const filesFilter = (opt, files) => {
58
- const map = new Map(files.map(f => [stripSlash(f), true]))
57
+ const map = new Map(files.map(f => [f.replace(/\/+$/, ''), true]))
59
58
  const filter = opt.filter
60
59
 
61
60
  const mapHas = (file, r) => {
@@ -69,8 +68,8 @@ const filesFilter = (opt, files) => {
69
68
  }
70
69
 
71
70
  opt.filter = filter
72
- ? (file, entry) => filter(file, entry) && mapHas(stripSlash(file))
73
- : file => mapHas(stripSlash(file))
71
+ ? (file, entry) => filter(file, entry) && mapHas(file.replace(/\/+$/, ''))
72
+ : file => mapHas(file.replace(/\/+$/, ''))
74
73
  }
75
74
 
76
75
  const listFileSync = opt => {
package/lib/mkdir.js CHANGED
@@ -8,7 +8,6 @@ const mkdirp = require('mkdirp')
8
8
  const fs = require('fs')
9
9
  const path = require('path')
10
10
  const chownr = require('chownr')
11
- const normPath = require('./normalize-windows-path.js')
12
11
 
13
12
  class SymlinkError extends Error {
14
13
  constructor (symlink, path) {
@@ -34,20 +33,7 @@ class CwdError extends Error {
34
33
  }
35
34
  }
36
35
 
37
- const cGet = (cache, key) => cache.get(normPath(key))
38
- const cSet = (cache, key, val) => cache.set(normPath(key), val)
39
-
40
- const checkCwd = (dir, cb) => {
41
- fs.stat(dir, (er, st) => {
42
- if (er || !st.isDirectory())
43
- er = new CwdError(dir, er && er.code || 'ENOTDIR')
44
- cb(er)
45
- })
46
- }
47
-
48
- module.exports = (dir, opt, cb) => {
49
- dir = normPath(dir)
50
-
36
+ const mkdir = module.exports = (dir, opt, cb) => {
51
37
  // if there's any overlap between mask and mode,
52
38
  // then we'll need an explicit chmod
53
39
  const umask = opt.umask
@@ -63,13 +49,13 @@ module.exports = (dir, opt, cb) => {
63
49
  const preserve = opt.preserve
64
50
  const unlink = opt.unlink
65
51
  const cache = opt.cache
66
- const cwd = normPath(opt.cwd)
52
+ const cwd = opt.cwd
67
53
 
68
54
  const done = (er, created) => {
69
55
  if (er)
70
56
  cb(er)
71
57
  else {
72
- cSet(cache, dir, true)
58
+ cache.set(dir, true)
73
59
  if (created && doChown)
74
60
  chownr(created, uid, gid, er => done(er))
75
61
  else if (needChmod)
@@ -79,17 +65,21 @@ module.exports = (dir, opt, cb) => {
79
65
  }
80
66
  }
81
67
 
82
- if (cache && cGet(cache, dir) === true)
68
+ if (cache && cache.get(dir) === true)
83
69
  return done()
84
70
 
85
71
  if (dir === cwd)
86
- return checkCwd(dir, done)
72
+ return fs.stat(dir, (er, st) => {
73
+ if (er || !st.isDirectory())
74
+ er = new CwdError(dir, er && er.code || 'ENOTDIR')
75
+ done(er)
76
+ })
87
77
 
88
78
  if (preserve)
89
- return mkdirp(dir, mode, done)
79
+ return mkdirp(dir, {mode}).then(made => done(null, made), done)
90
80
 
91
- const sub = normPath(path.relative(cwd, dir))
92
- const parts = sub.split('/')
81
+ const sub = path.relative(cwd, dir)
82
+ const parts = sub.split(/\/|\\/)
93
83
  mkdir_(cwd, parts, mode, cache, unlink, cwd, null, done)
94
84
  }
95
85
 
@@ -97,19 +87,22 @@ const mkdir_ = (base, parts, mode, cache, unlink, cwd, created, cb) => {
97
87
  if (!parts.length)
98
88
  return cb(null, created)
99
89
  const p = parts.shift()
100
- const part = normPath(path.resolve(base + '/' + p))
101
- if (cGet(cache, part))
90
+ const part = base + '/' + p
91
+ if (cache.get(part))
102
92
  return mkdir_(part, parts, mode, cache, unlink, cwd, created, cb)
103
93
  fs.mkdir(part, mode, onmkdir(part, parts, mode, cache, unlink, cwd, created, cb))
104
94
  }
105
95
 
106
96
  const onmkdir = (part, parts, mode, cache, unlink, cwd, created, cb) => er => {
107
97
  if (er) {
98
+ if (er.path && path.dirname(er.path) === cwd &&
99
+ (er.code === 'ENOTDIR' || er.code === 'ENOENT'))
100
+ return cb(new CwdError(cwd, er.code))
101
+
108
102
  fs.lstat(part, (statEr, st) => {
109
- if (statEr) {
110
- statEr.path = statEr.path && normPath(statEr.path)
103
+ if (statEr)
111
104
  cb(statEr)
112
- } else if (st.isDirectory())
105
+ else if (st.isDirectory())
113
106
  mkdir_(part, parts, mode, cache, unlink, cwd, created, cb)
114
107
  else if (unlink)
115
108
  fs.unlink(part, er => {
@@ -128,21 +121,7 @@ const onmkdir = (part, parts, mode, cache, unlink, cwd, created, cb) => er => {
128
121
  }
129
122
  }
130
123
 
131
- const checkCwdSync = dir => {
132
- let ok = false
133
- let code = 'ENOTDIR'
134
- try {
135
- ok = fs.statSync(dir).isDirectory()
136
- } catch (er) {
137
- code = er.code
138
- } finally {
139
- if (!ok)
140
- throw new CwdError(dir, code)
141
- }
142
- }
143
-
144
- module.exports.sync = (dir, opt) => {
145
- dir = normPath(dir)
124
+ const mkdirSync = module.exports.sync = (dir, opt) => {
146
125
  // if there's any overlap between mask and mode,
147
126
  // then we'll need an explicit chmod
148
127
  const umask = opt.umask
@@ -158,51 +137,65 @@ module.exports.sync = (dir, opt) => {
158
137
  const preserve = opt.preserve
159
138
  const unlink = opt.unlink
160
139
  const cache = opt.cache
161
- const cwd = normPath(opt.cwd)
140
+ const cwd = opt.cwd
162
141
 
163
142
  const done = (created) => {
164
- cSet(cache, dir, true)
143
+ cache.set(dir, true)
165
144
  if (created && doChown)
166
145
  chownr.sync(created, uid, gid)
167
146
  if (needChmod)
168
147
  fs.chmodSync(dir, mode)
169
148
  }
170
149
 
171
- if (cache && cGet(cache, dir) === true)
150
+ if (cache && cache.get(dir) === true)
172
151
  return done()
173
152
 
174
153
  if (dir === cwd) {
175
- checkCwdSync(cwd)
176
- return done()
154
+ let ok = false
155
+ let code = 'ENOTDIR'
156
+ try {
157
+ ok = fs.statSync(dir).isDirectory()
158
+ } catch (er) {
159
+ code = er.code
160
+ } finally {
161
+ if (!ok)
162
+ throw new CwdError(dir, code)
163
+ }
164
+ done()
165
+ return
177
166
  }
178
167
 
179
168
  if (preserve)
180
169
  return done(mkdirp.sync(dir, mode))
181
170
 
182
- const sub = normPath(path.relative(cwd, dir))
183
- const parts = sub.split('/')
171
+ const sub = path.relative(cwd, dir)
172
+ const parts = sub.split(/\/|\\/)
184
173
  let created = null
185
174
  for (let p = parts.shift(), part = cwd;
186
- p && (part += '/' + p);
187
- p = parts.shift()) {
188
- part = normPath(path.resolve(part))
189
- if (cGet(cache, part))
175
+ p && (part += '/' + p);
176
+ p = parts.shift()) {
177
+
178
+ if (cache.get(part))
190
179
  continue
191
180
 
192
181
  try {
193
182
  fs.mkdirSync(part, mode)
194
183
  created = created || part
195
- cSet(cache, part, true)
184
+ cache.set(part, true)
196
185
  } catch (er) {
186
+ if (er.path && path.dirname(er.path) === cwd &&
187
+ (er.code === 'ENOTDIR' || er.code === 'ENOENT'))
188
+ return new CwdError(cwd, er.code)
189
+
197
190
  const st = fs.lstatSync(part)
198
191
  if (st.isDirectory()) {
199
- cSet(cache, part, true)
192
+ cache.set(part, true)
200
193
  continue
201
194
  } else if (unlink) {
202
195
  fs.unlinkSync(part)
203
196
  fs.mkdirSync(part, mode)
204
197
  created = created || part
205
- cSet(cache, part, true)
198
+ cache.set(part, true)
206
199
  continue
207
200
  } else if (st.isSymbolicLink())
208
201
  return new SymlinkError(part, part + '/' + parts.join('/'))
package/lib/pack.js CHANGED
@@ -54,7 +54,6 @@ const ONDRAIN = Symbol('ondrain')
54
54
  const fs = require('fs')
55
55
  const path = require('path')
56
56
  const warner = require('./warn-mixin.js')
57
- const normPath = require('./normalize-windows-path.js')
58
57
 
59
58
  const Pack = warner(class Pack extends MiniPass {
60
59
  constructor (opt) {
@@ -67,7 +66,7 @@ const Pack = warner(class Pack extends MiniPass {
67
66
  this.preservePaths = !!opt.preservePaths
68
67
  this.strict = !!opt.strict
69
68
  this.noPax = !!opt.noPax
70
- this.prefix = normPath(opt.prefix || '')
69
+ this.prefix = (opt.prefix || '').replace(/(\\|\/)+$/, '')
71
70
  this.linkCache = opt.linkCache || new Map()
72
71
  this.statCache = opt.statCache || new Map()
73
72
  this.readdirCache = opt.readdirCache || new Map()
@@ -134,7 +133,10 @@ const Pack = warner(class Pack extends MiniPass {
134
133
  }
135
134
 
136
135
  [ADDTARENTRY] (p) {
137
- const absolute = normPath(path.resolve(this.cwd, p.path))
136
+ const absolute = path.resolve(this.cwd, p.path)
137
+ if (this.prefix)
138
+ p.path = this.prefix + '/' + p.path.replace(/^\.(\/+|$)/, '')
139
+
138
140
  // in this case, we don't have to wait for the stat
139
141
  if (!this.filter(p.path, p))
140
142
  p.resume()
@@ -150,7 +152,10 @@ const Pack = warner(class Pack extends MiniPass {
150
152
  }
151
153
 
152
154
  [ADDFSENTRY] (p) {
153
- const absolute = normPath(path.resolve(this.cwd, p))
155
+ const absolute = path.resolve(this.cwd, p)
156
+ if (this.prefix)
157
+ p = this.prefix + '/' + p.replace(/^\.(\/+|$)/, '')
158
+
154
159
  this[QUEUE].push(new PackJob(p, absolute))
155
160
  this[PROCESS]()
156
161
  }
@@ -292,8 +297,7 @@ const Pack = warner(class Pack extends MiniPass {
292
297
  linkCache: this.linkCache,
293
298
  statCache: this.statCache,
294
299
  noMtime: this.noMtime,
295
- mtime: this.mtime,
296
- prefix: this.prefix,
300
+ mtime: this.mtime
297
301
  }
298
302
  }
299
303
 
@@ -319,7 +323,10 @@ const Pack = warner(class Pack extends MiniPass {
319
323
 
320
324
  if (job.readdir)
321
325
  job.readdir.forEach(entry => {
322
- const p = job.path
326
+ const p = this.prefix ?
327
+ job.path.slice(this.prefix.length + 1) || './'
328
+ : job.path
329
+
323
330
  const base = p === './' ? '' : p.replace(/\/*$/, '/')
324
331
  this[ADDFSENTRY](base + entry)
325
332
  })
@@ -372,7 +379,10 @@ class PackSync extends Pack {
372
379
 
373
380
  if (job.readdir)
374
381
  job.readdir.forEach(entry => {
375
- const p = job.path
382
+ const p = this.prefix ?
383
+ job.path.slice(this.prefix.length + 1) || './'
384
+ : job.path
385
+
376
386
  const base = p === './' ? '' : p.replace(/\/*$/, '/')
377
387
  this[ADDFSENTRY](base + entry)
378
388
  })
@@ -7,12 +7,6 @@
7
7
  // while still allowing maximal safe parallelization.
8
8
 
9
9
  const assert = require('assert')
10
- const normPath = require('./normalize-windows-path.js')
11
- const stripSlashes = require('./strip-trailing-slashes.js')
12
- const { join } = require('path')
13
-
14
- const platform = process.env.TESTING_TAR_FAKE_PLATFORM || process.platform
15
- const isWindows = platform === 'win32'
16
10
 
17
11
  module.exports = () => {
18
12
  // path => [function or Set]
@@ -24,16 +18,10 @@ module.exports = () => {
24
18
  const reservations = new Map()
25
19
 
26
20
  // return a set of parent dirs for a given path
27
- // '/a/b/c/d' -> ['/', '/a', '/a/b', '/a/b/c', '/a/b/c/d']
28
- const getDirs = path => {
29
- const dirs = path.split('/').slice(0, -1).reduce((set, path) => {
30
- if (set.length)
31
- path = normPath(join(set[set.length - 1], path))
32
- set.push(path || '/')
33
- return set
34
- }, [])
35
- return dirs
36
- }
21
+ const { join } = require('path')
22
+ const getDirs = path =>
23
+ join(path).split(/[\\\/]/).slice(0, -1).reduce((set, path) =>
24
+ set.length ? set.concat(join(set[set.length-1], path)) : [path], [])
37
25
 
38
26
  // functions currently running
39
27
  const running = new Set()
@@ -109,18 +97,6 @@ module.exports = () => {
109
97
  }
110
98
 
111
99
  const reserve = (paths, fn) => {
112
- // collide on matches across case and unicode normalization
113
- // On windows, thanks to the magic of 8.3 shortnames, it is fundamentally
114
- // impossible to determine whether two paths refer to the same thing on
115
- // disk, without asking the kernel for a shortname.
116
- // So, we just pretend that every path matches every other path here,
117
- // effectively removing all parallelization on windows.
118
- paths = isWindows ? ['win32 parallelization disabled'] : paths.map(p => {
119
- return stripSlashes(normPath(join(p)))
120
- .normalize('NFKD')
121
- .toLowerCase()
122
- })
123
-
124
100
  const dirs = new Set(
125
101
  paths.map(path => getDirs(path)).reduce((a, b) => a.concat(b))
126
102
  )
package/lib/read-entry.js CHANGED
@@ -1,7 +1,6 @@
1
1
  'use strict'
2
2
  const types = require('./types.js')
3
3
  const MiniPass = require('minipass')
4
- const normPath = require('./normalize-windows-path.js')
5
4
 
6
5
  const SLURP = Symbol('slurp')
7
6
  module.exports = class ReadEntry extends MiniPass {
@@ -48,7 +47,7 @@ module.exports = class ReadEntry extends MiniPass {
48
47
  this.ignore = true
49
48
  }
50
49
 
51
- this.path = normPath(header.path)
50
+ this.path = header.path
52
51
  this.mode = header.mode
53
52
  if (this.mode)
54
53
  this.mode = this.mode & 0o7777
@@ -60,7 +59,7 @@ module.exports = class ReadEntry extends MiniPass {
60
59
  this.mtime = header.mtime
61
60
  this.atime = header.atime
62
61
  this.ctime = header.ctime
63
- this.linkpath = normPath(header.linkpath)
62
+ this.linkpath = header.linkpath
64
63
  this.uname = header.uname
65
64
  this.gname = header.gname
66
65
 
@@ -93,7 +92,7 @@ module.exports = class ReadEntry extends MiniPass {
93
92
  // a global extended header, because that's weird.
94
93
  if (ex[k] !== null && ex[k] !== undefined &&
95
94
  !(global && k === 'path'))
96
- this[k] = k === 'path' || k === 'linkpath' ? normPath(ex[k]) : ex[k]
95
+ this[k] = ex[k]
97
96
  }
98
97
  }
99
98
  }
package/lib/replace.js CHANGED
@@ -167,8 +167,7 @@ const replace = (opt, files, cb) => {
167
167
 
168
168
  fs.fstat(fd, (er, st) => {
169
169
  if (er)
170
- return fs.close(fd, () => reject(er))
171
-
170
+ return reject(er)
172
171
  getPos(fd, st.size, (er, position) => {
173
172
  if (er)
174
173
  return reject(er)