tar 6.1.5 → 6.1.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/lib/pack.js CHANGED
@@ -134,9 +134,6 @@ const Pack = warner(class Pack extends MiniPass {
134
134
 
135
135
  [ADDTARENTRY] (p) {
136
136
  const absolute = path.resolve(this.cwd, p.path)
137
- if (this.prefix)
138
- p.path = this.prefix + '/' + p.path.replace(/^\.(\/+|$)/, '')
139
-
140
137
  // in this case, we don't have to wait for the stat
141
138
  if (!this.filter(p.path, p))
142
139
  p.resume()
@@ -153,9 +150,6 @@ const Pack = warner(class Pack extends MiniPass {
153
150
 
154
151
  [ADDFSENTRY] (p) {
155
152
  const absolute = path.resolve(this.cwd, p)
156
- if (this.prefix)
157
- p = this.prefix + '/' + p.replace(/^\.(\/+|$)/, '')
158
-
159
153
  this[QUEUE].push(new PackJob(p, absolute))
160
154
  this[PROCESS]()
161
155
  }
@@ -298,6 +292,7 @@ const Pack = warner(class Pack extends MiniPass {
298
292
  statCache: this.statCache,
299
293
  noMtime: this.noMtime,
300
294
  mtime: this.mtime,
295
+ prefix: this.prefix,
301
296
  }
302
297
  }
303
298
 
@@ -323,10 +318,7 @@ const Pack = warner(class Pack extends MiniPass {
323
318
 
324
319
  if (job.readdir) {
325
320
  job.readdir.forEach(entry => {
326
- const p = this.prefix ?
327
- job.path.slice(this.prefix.length + 1) || './'
328
- : job.path
329
-
321
+ const p = job.path
330
322
  const base = p === './' ? '' : p.replace(/\/*$/, '/')
331
323
  this[ADDFSENTRY](base + entry)
332
324
  })
@@ -381,10 +373,7 @@ class PackSync extends Pack {
381
373
 
382
374
  if (job.readdir) {
383
375
  job.readdir.forEach(entry => {
384
- const p = this.prefix ?
385
- job.path.slice(this.prefix.length + 1) || './'
386
- : job.path
387
-
376
+ const p = job.path
388
377
  const base = p === './' ? '' : p.replace(/\/*$/, '/')
389
378
  this[ADDFSENTRY](base + entry)
390
379
  })
@@ -5,6 +5,13 @@ const Header = require('./header.js')
5
5
  const fs = require('fs')
6
6
  const path = require('path')
7
7
 
8
+ const prefixPath = (path, prefix) => {
9
+ if (!prefix)
10
+ return path
11
+ path = path.replace(/^\.([/\\]|$)/, '')
12
+ return prefix + '/' + path
13
+ }
14
+
8
15
  const maxReadSize = 16 * 1024 * 1024
9
16
  const PROCESS = Symbol('process')
10
17
  const FILE = Symbol('file')
@@ -23,6 +30,7 @@ const CLOSE = Symbol('close')
23
30
  const MODE = Symbol('mode')
24
31
  const AWAITDRAIN = Symbol('awaitDrain')
25
32
  const ONDRAIN = Symbol('ondrain')
33
+ const PREFIX = Symbol('prefix')
26
34
  const warner = require('./warn-mixin.js')
27
35
  const winchars = require('./winchars.js')
28
36
  const stripAbsolutePath = require('./strip-absolute-path.js')
@@ -50,6 +58,7 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
50
58
  this.noPax = !!opt.noPax
51
59
  this.noMtime = !!opt.noMtime
52
60
  this.mtime = opt.mtime || null
61
+ this.prefix = opt.prefix || null
53
62
 
54
63
  this.fd = null
55
64
  this.blockLen = null
@@ -128,13 +137,19 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
128
137
  return modeFix(mode, this.type === 'Directory', this.portable)
129
138
  }
130
139
 
140
+ [PREFIX] (path) {
141
+ return prefixPath(path, this.prefix)
142
+ }
143
+
131
144
  [HEADER] () {
132
145
  if (this.type === 'Directory' && this.portable)
133
146
  this.noMtime = true
134
147
 
135
148
  this.header = new Header({
136
- path: this.path,
137
- linkpath: this.linkpath,
149
+ path: this[PREFIX](this.path),
150
+ // only apply the prefix to hard links.
151
+ linkpath: this.type === 'Link' ? this[PREFIX](this.linkpath)
152
+ : this.linkpath,
138
153
  // only the permissions and setuid/setgid/sticky bitflags
139
154
  // not the higher-order bits that specify file type
140
155
  mode: this[MODE](this.stat.mode),
@@ -155,8 +170,9 @@ const WriteEntry = warner(class WriteEntry extends MiniPass {
155
170
  ctime: this.portable ? null : this.header.ctime,
156
171
  gid: this.portable ? null : this.header.gid,
157
172
  mtime: this.noMtime ? null : this.mtime || this.header.mtime,
158
- path: this.path,
159
- linkpath: this.linkpath,
173
+ path: this[PREFIX](this.path),
174
+ linkpath: this.type === 'Link' ? this[PREFIX](this.linkpath)
175
+ : this.linkpath,
160
176
  size: this.header.size,
161
177
  uid: this.portable ? null : this.header.uid,
162
178
  uname: this.portable ? null : this.header.uname,
@@ -385,6 +401,8 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
385
401
  if (this.type === 'Directory' && this.portable)
386
402
  this.noMtime = true
387
403
 
404
+ this.prefix = opt.prefix || null
405
+
388
406
  this.path = readEntry.path
389
407
  this.mode = this[MODE](readEntry.mode)
390
408
  this.uid = this.portable ? null : readEntry.uid
@@ -413,8 +431,9 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
413
431
  this.blockRemain = readEntry.startBlockSize
414
432
 
415
433
  this.header = new Header({
416
- path: this.path,
417
- linkpath: this.linkpath,
434
+ path: this[PREFIX](this.path),
435
+ linkpath: this.type === 'Link' ? this[PREFIX](this.linkpath)
436
+ : this.linkpath,
418
437
  // only the permissions and setuid/setgid/sticky bitflags
419
438
  // not the higher-order bits that specify file type
420
439
  mode: this.mode,
@@ -441,8 +460,9 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
441
460
  ctime: this.portable ? null : this.ctime,
442
461
  gid: this.portable ? null : this.gid,
443
462
  mtime: this.noMtime ? null : this.mtime,
444
- path: this.path,
445
- linkpath: this.linkpath,
463
+ path: this[PREFIX](this.path),
464
+ linkpath: this.type === 'Link' ? this[PREFIX](this.linkpath)
465
+ : this.linkpath,
446
466
  size: this.size,
447
467
  uid: this.portable ? null : this.uid,
448
468
  uname: this.portable ? null : this.uname,
@@ -456,6 +476,10 @@ const WriteEntryTar = warner(class WriteEntryTar extends MiniPass {
456
476
  readEntry.pipe(this)
457
477
  }
458
478
 
479
+ [PREFIX] (path) {
480
+ return prefixPath(path, this.prefix)
481
+ }
482
+
459
483
  [MODE] (mode) {
460
484
  return modeFix(mode, this.type === 'Directory', this.portable)
461
485
  }
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",
5
+ "version": "6.1.6",
6
6
  "repository": {
7
7
  "type": "git",
8
8
  "url": "https://github.com/npm/node-tar.git"