[Pkg-javascript-commits] [node-tar] 01/07: Imported Upstream version 2.2.1

Jérémy Lal kapouer at moszumanska.debian.org
Thu Nov 17 20:59:07 UTC 2016


This is an automated email from the git hooks/post-receive script.

kapouer pushed a commit to branch master
in repository node-tar.

commit c5e73f4f7d942ac9c69cff9d6735a3e595645d6a
Author: Jérémy Lal <kapouer at melix.org>
Date:   Sun Jan 3 17:13:32 2016 +0100

    Imported Upstream version 2.2.1
---
 LICENCE                        |  25 ------
 LICENSE                        |  12 +++
 README.md                      |   4 +-
 lib/entry.js                   |   7 ++
 lib/extract.js                 |  24 ++++--
 lib/pack.js                    |   7 +-
 lib/parse.js                   |   8 +-
 package.json                   |   6 +-
 test/cb-never-called-1.0.1.tgz | Bin 0 -> 4096 bytes
 test/dir-normalization.js      | 177 +++++++++++++++++++++++++++++++++++++++++
 test/dir-normalization.tar     | Bin 0 -> 4608 bytes
 test/error-on-broken.js        |  33 ++++++++
 test/pack.js                   |  22 ++++-
 test/parse-discard.js          |  29 +++++++
 14 files changed, 312 insertions(+), 42 deletions(-)

diff --git a/LICENCE b/LICENCE
deleted file mode 100644
index 74489e2..0000000
--- a/LICENCE
+++ /dev/null
@@ -1,25 +0,0 @@
-Copyright (c) Isaac Z. Schlueter
-All rights reserved.
-
-The BSD License
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
-   notice, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
-   notice, this list of conditions and the following disclaimer in the
-   documentation and/or other materials provided with the distribution.
-
-THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
-``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
-TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
-PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
-BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
-CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
-INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
-CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
-ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
-POSSIBILITY OF SUCH DAMAGE.
diff --git a/LICENSE b/LICENSE
new file mode 100644
index 0000000..019b7e4
--- /dev/null
+++ b/LICENSE
@@ -0,0 +1,12 @@
+The ISC License
+Copyright (c) Isaac Z. Schlueter and Contributors
+Permission to use, copy, modify, and/or distribute this software for any
+purpose with or without fee is hereby granted, provided that the above
+copyright notice and this permission notice appear in all copies.
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR
+IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
diff --git a/README.md b/README.md
index 424a278..cfda2ac 100644
--- a/README.md
+++ b/README.md
@@ -22,7 +22,9 @@ stream.
 This only works with directories, it does not work with individual files.
 
 The optional `properties` object are used to set properties in the tar
-'Global Extended Header'.
+'Global Extended Header'. If the `fromBase` property is set to true,
+the tar will contain files relative to the path passed, and not with
+the path included.
 
 ### tar.Extract([options])
 
diff --git a/lib/entry.js b/lib/entry.js
index 4af5c41..591202b 100644
--- a/lib/entry.js
+++ b/lib/entry.js
@@ -24,6 +24,7 @@ function Entry (header, extended, global) {
   this._ending = false
   this._ended = false
   this._remaining = 0
+  this._abort = false
   this._queue = []
   this._index = 0
   this._queueLen = 0
@@ -209,5 +210,11 @@ Entry.prototype._setProps = function () {
   this._remaining = props.size
 }
 
+// the parser may not call write if _abort is true. 
+// useful for skipping data from some files quickly.
+Entry.prototype.abort = function(){
+  this._abort = true
+}
+
 Entry.prototype.warn = fstream.warn
 Entry.prototype.error = fstream.error
diff --git a/lib/extract.js b/lib/extract.js
index 9fb1e6f..fe1bb97 100644
--- a/lib/extract.js
+++ b/lib/extract.js
@@ -11,10 +11,6 @@ function Extract (opts) {
   if (!(this instanceof Extract)) return new Extract(opts)
   tar.Parse.apply(this)
 
-  // have to dump into a directory
-  opts.type = "Directory"
-  opts.Directory = true
-
   if (typeof opts !== "object") {
     opts = { path: opts }
   }
@@ -47,9 +43,20 @@ function Extract (opts) {
         entry.linkpath = entry.props.linkpath = lp
       }
     }
-    if (entry.type !== "Link") return
-    entry.linkpath = entry.props.linkpath =
-      path.join(opts.path, path.join("/", entry.props.linkpath))
+    if (entry.type === "Link") {
+      entry.linkpath = entry.props.linkpath =
+        path.join(opts.path, path.join("/", entry.props.linkpath))
+    }
+
+    if (entry.type === "SymbolicLink") {
+      var dn = path.dirname(entry.path) || ""
+      var linkpath = entry.props.linkpath
+      var target = path.resolve(opts.path, dn, linkpath)
+      if (target.indexOf(opts.path) !== 0) {
+        linkpath = path.join(opts.path, path.join("/", linkpath))
+      }
+      entry.linkpath = entry.props.linkpath = linkpath
+    }
   })
 
   this._fst.on("ready", function () {
@@ -71,6 +78,7 @@ function Extract (opts) {
 
   this._fst.on("close", function () {
     // console.error("\nEEEE Extract End", me._fst.path)
+    me.emit("finish")
     me.emit("end")
     me.emit("close")
   })
@@ -80,7 +88,7 @@ inherits(Extract, tar.Parse)
 
 Extract.prototype._streamEnd = function () {
   var me = this
-  if (!me._ended) me.error("unexpected eof")
+  if (!me._ended || me._entry) me.error("unexpected eof")
   me._fst.end()
   // my .end() is coming later.
 }
diff --git a/lib/pack.js b/lib/pack.js
index 3ff14dd..5a3bb95 100644
--- a/lib/pack.js
+++ b/lib/pack.js
@@ -131,7 +131,12 @@ Pack.prototype._process = function () {
   // in the tarball to use.  That way we can skip a lot of extra
   // work when resolving symlinks for bundled dependencies in npm.
 
-  var root = path.dirname((entry.root || entry).path)
+  var root = path.dirname((entry.root || entry).path);
+  if (me._global && me._global.fromBase && entry.root && entry.root.path) {
+    // user set 'fromBase: true' indicating tar root should be directory itself
+    root = entry.root.path;
+  }
+
   var wprops = {}
 
   Object.keys(entry.props || {}).forEach(function (k) {
diff --git a/lib/parse.js b/lib/parse.js
index 8517c48..600ad78 100644
--- a/lib/parse.js
+++ b/lib/parse.js
@@ -61,7 +61,7 @@ function Parse () {
 // emitting "end"
 Parse.prototype._streamEnd = function () {
   var me = this
-  if (!me._ended) me.error("unexpected eof")
+  if (!me._ended || me._entry) me.error("unexpected eof")
   me.emit("end")
 }
 
@@ -102,7 +102,11 @@ Parse.prototype._process = function (c) {
 
   if (this._entry) {
     var entry = this._entry
-    entry.write(c)
+    if(!entry._abort) entry.write(c)
+    else {
+      entry._remaining -= c.length
+      if(entry._remaining < 0) entry._remaining = 0
+    }
     if (entry._remaining === 0) {
       entry.end()
       this._entry = null
diff --git a/package.json b/package.json
index 61fc2f0..c5b999b 100644
--- a/package.json
+++ b/package.json
@@ -2,7 +2,7 @@
   "author": "Isaac Z. Schlueter <i at izs.me> (http://blog.izs.me/)",
   "name": "tar",
   "description": "tar for node",
-  "version": "1.0.3",
+  "version": "2.2.1",
   "repository": {
     "type": "git",
     "url": "git://github.com/isaacs/node-tar.git"
@@ -17,10 +17,10 @@
     "inherits": "2"
   },
   "devDependencies": {
-    "graceful-fs": "^3.0.2",
+    "graceful-fs": "^4.1.2",
     "rimraf": "1.x",
     "tap": "0.x",
     "mkdirp": "^0.5.0"
   },
-  "license": "BSD"
+  "license": "ISC"
 }
diff --git a/test/cb-never-called-1.0.1.tgz b/test/cb-never-called-1.0.1.tgz
new file mode 100644
index 0000000..9e7014d
Binary files /dev/null and b/test/cb-never-called-1.0.1.tgz differ
diff --git a/test/dir-normalization.js b/test/dir-normalization.js
new file mode 100644
index 0000000..9719c42
--- /dev/null
+++ b/test/dir-normalization.js
@@ -0,0 +1,177 @@
+// Set the umask, so that it works the same everywhere.
+process.umask(parseInt('22', 8))
+
+var fs = require('fs')
+var path = require('path')
+
+var fstream = require('fstream')
+var test = require('tap').test
+
+var tar = require('../tar.js')
+var file = path.resolve(__dirname, 'dir-normalization.tar')
+var target = path.resolve(__dirname, 'tmp/dir-normalization-test')
+var ee = 0
+
+var expectEntries = [
+  { path: 'fixtures/',
+    mode: '755',
+    type: '5',
+    linkpath: ''
+  },
+  { path: 'fixtures/a/',
+    mode: '755',
+    type: '5',
+    linkpath: ''
+  },
+  { path: 'fixtures/the-chumbler',
+    mode: '755',
+    type: '2',
+    linkpath: path.resolve(target, 'a/b/c/d/the-chumbler'),
+  },
+  { path: 'fixtures/a/b/',
+    mode: '755',
+    type: '5',
+    linkpath: ''
+  },
+  { path: 'fixtures/a/x',
+    mode: '644',
+    type: '0',
+    linkpath: ''
+  },
+  { path: 'fixtures/a/b/c/',
+    mode: '755',
+    type: '5',
+    linkpath: ''
+  },
+  { path: 'fixtures/a/b/c/y',
+    mode: '755',
+    type: '2',
+    linkpath: '../../x',
+  }
+]
+
+var ef = 0
+var expectFiles = [
+  { path: '',
+    mode: '40755',
+    type: 'Directory',
+    depth: 0,
+    linkpath: undefined
+  },
+  { path: '/fixtures',
+    mode: '40755',
+    type: 'Directory',
+    depth: 1,
+    linkpath: undefined
+  },
+  { path: '/fixtures/a',
+    mode: '40755',
+    type: 'Directory',
+    depth: 2,
+    linkpath: undefined
+  },
+  { path: '/fixtures/a/b',
+    mode: '40755',
+    type: 'Directory',
+    depth: 3,
+    linkpath: undefined
+  },
+  { path: '/fixtures/a/b/c',
+    mode: '40755',
+    type: 'Directory',
+    depth: 4,
+    linkpath: undefined
+  },
+  { path: '/fixtures/a/b/c/y',
+    mode: '120755',
+    type: 'SymbolicLink',
+    depth: 5,
+    linkpath: '../../x'
+  },
+  { path: '/fixtures/a/x',
+    mode: '100644',
+    type: 'File',
+    depth: 3,
+    linkpath: undefined
+  },
+  { path: '/fixtures/the-chumbler',
+    mode: '120755',
+    type: 'SymbolicLink',
+    depth: 2,
+    linkpath: path.resolve(target, 'a/b/c/d/the-chumbler')
+  }
+]
+
+test('preclean', function (t) {
+  require('rimraf').sync(path.join(__dirname, '/tmp/dir-normalization-test'))
+  t.pass('cleaned!')
+  t.end()
+})
+
+test('extract test', function (t) {
+  var extract = tar.Extract(target)
+  var inp = fs.createReadStream(file)
+
+  inp.pipe(extract)
+
+  extract.on('end', function () {
+    t.equal(ee, expectEntries.length, 'should see ' + expectEntries.length + ' entries')
+
+    // should get no more entries after end
+    extract.removeAllListeners('entry')
+    extract.on('entry', function (e) {
+      t.fail('Should not get entries after end!')
+    })
+
+    next()
+  })
+
+  extract.on('entry', function (entry) {
+    var mode = entry.props.mode & (~parseInt('22', 8))
+    var found = {
+      path: entry.path,
+      mode: mode.toString(8),
+      type: entry.props.type,
+      linkpath: entry.props.linkpath,
+    }
+
+    var wanted = expectEntries[ee++]
+    t.equivalent(found, wanted, 'tar entry ' + ee + ' ' + (wanted && wanted.path))
+  })
+
+  function next () {
+    var r = fstream.Reader({
+      path: target,
+      type: 'Directory',
+      sort: 'alpha'
+    })
+
+    r.on('ready', function () {
+      foundEntry(r)
+    })
+
+    r.on('end', finish)
+
+    function foundEntry (entry) {
+      var p = entry.path.substr(target.length)
+      var mode = entry.props.mode & (~parseInt('22', 8))
+      var found = {
+        path: p,
+        mode: mode.toString(8),
+        type: entry.props.type,
+        depth: entry.props.depth,
+        linkpath: entry.props.linkpath
+      }
+
+      var wanted = expectFiles[ef++]
+      t.equivalent(found, wanted, 'unpacked file ' + ef + ' ' + (wanted && wanted.path))
+
+      entry.on('entry', foundEntry)
+    }
+
+    function finish () {
+      t.equal(ef, expectFiles.length, 'should have ' + ef + ' items')
+      t.end()
+    }
+  }
+})
diff --git a/test/dir-normalization.tar b/test/dir-normalization.tar
new file mode 100644
index 0000000..3c48453
Binary files /dev/null and b/test/dir-normalization.tar differ
diff --git a/test/error-on-broken.js b/test/error-on-broken.js
new file mode 100644
index 0000000..e484920
--- /dev/null
+++ b/test/error-on-broken.js
@@ -0,0 +1,33 @@
+var fs = require('fs')
+var path = require('path')
+var zlib = require('zlib')
+
+var tap = require('tap')
+
+var tar = require('../tar.js')
+
+var file = path.join(__dirname, 'cb-never-called-1.0.1.tgz')
+var target = path.join(__dirname, 'tmp/extract-test')
+
+tap.test('preclean', function (t) {
+  require('rimraf').sync(__dirname + '/tmp/extract-test')
+  t.pass('cleaned!')
+  t.end()
+})
+
+tap.test('extract test', function (t) {
+  var extract = tar.Extract(target)
+  var inp = fs.createReadStream(file)
+
+  inp.pipe(zlib.createGunzip()).pipe(extract)
+
+  extract.on('error', function (er) {
+    t.equal(er.message, 'unexpected eof', 'error noticed')
+    t.end()
+  })
+
+  extract.on('end', function () {
+    t.fail('shouldn\'t reach this point due to errors')
+    t.end()
+  })
+})
diff --git a/test/pack.js b/test/pack.js
index bf033c1..0f16c07 100644
--- a/test/pack.js
+++ b/test/pack.js
@@ -830,6 +830,10 @@ tap.test("without global header", { timeout: 10000 }, function (t) {
   runTest(t, false)
 })
 
+tap.test("with from base", { timeout: 10000 }, function (t) {
+  runTest(t, true, true)
+})
+
 function alphasort (a, b) {
   return a === b ? 0
        : a.toLowerCase() > b.toLowerCase() ? 1
@@ -839,7 +843,7 @@ function alphasort (a, b) {
 }
 
 
-function runTest (t, doGH) {
+function runTest (t, doGH, doFromBase) {
   var reader = Reader({ path: input
                       , filter: function () {
                           return !this.path.match(/\.(tar|hex)$/)
@@ -847,7 +851,10 @@ function runTest (t, doGH) {
                       , sort: alphasort
                       })
 
-  var pack = Pack(doGH ? pkg : null)
+  var props = doGH ? pkg : {}
+  if(doFromBase) props.fromBase = true;
+
+  var pack = Pack(props)
   var writer = Writer(target)
 
   // skip the global header if we're not doing that.
@@ -901,6 +908,17 @@ function runTest (t, doGH) {
     }
     t.equal(ev, wanted[0], "event type should be "+wanted[0])
 
+    if(doFromBase) {
+      if(wanted[1].path.indexOf('fixtures/') && wanted[1].path.length == 100)
+        wanted[1].path = wanted[1].path.replace('fixtures/', '') + 'ccccccccc'
+
+      if(wanted[1]) wanted[1].path = wanted[1].path.replace('fixtures/', '').replace('//', '/')
+      if(wanted[1].path == '') wanted[1].path = '/'
+      if(wanted[2] && wanted[2].path) wanted[2].path = wanted[2].path.replace('fixtures', '').replace(/^\//, '')
+
+      wanted[1].linkpath = wanted[1].linkpath.replace('fixtures/', '')
+    }
+
     if (ev !== wanted[0] || e.path !== wanted[1].path) {
       console.error("wanted", wanted)
       console.error([ev, e.props])
diff --git a/test/parse-discard.js b/test/parse-discard.js
new file mode 100644
index 0000000..da01a65
--- /dev/null
+++ b/test/parse-discard.js
@@ -0,0 +1,29 @@
+var tap = require("tap")
+  , tar = require("../tar.js")
+  , fs = require("fs")
+  , path = require("path")
+  , file = path.resolve(__dirname, "fixtures/c.tar")
+
+tap.test("parser test", function (t) {
+  var parser = tar.Parse()
+  var total = 0
+  var dataTotal = 0
+
+  parser.on("end", function () {
+
+    t.equals(total-513,dataTotal,'should have discarded only c.txt')
+
+    t.end()
+  })
+
+  fs.createReadStream(file)
+    .pipe(parser)
+    .on('entry',function(entry){
+      if(entry.path === 'c.txt') entry.abort()
+      
+      total += entry.size;
+      entry.on('data',function(data){
+        dataTotal += data.length        
+      })
+    })
+})

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/collab-maint/node-tar.git



More information about the Pkg-javascript-commits mailing list