1 // Set the umask, so that it works the same everywhere.
2 process.umask(parseInt('22', 8))
5 var path = require('path')
7 var fstream = require('fstream')
8 var test = require('tap').test
10 var tar = require('../tar.js')
11 var file = path.resolve(__dirname, 'dir-normalization.tar')
12 var target = path.resolve(__dirname, 'tmp/dir-normalization-test')
21 { path: 'fixtures/a/',
26 { path: 'fixtures/the-chumbler',
29 linkpath: path.resolve(target, 'a/b/c/d/the-chumbler'),
31 { path: 'fixtures/a/b/',
36 { path: 'fixtures/a/x',
41 { path: 'fixtures/a/b/c/',
46 { path: 'fixtures/a/b/c/y',
67 { path: '/fixtures/a',
73 { path: '/fixtures/a/b',
79 { path: '/fixtures/a/b/c',
85 { path: '/fixtures/a/b/c/y',
91 { path: '/fixtures/a/x',
97 { path: '/fixtures/the-chumbler',
101 linkpath: path.resolve(target, 'a/b/c/d/the-chumbler')
105 test('preclean', function (t) {
106 require('rimraf').sync(path.join(__dirname, '/tmp/dir-normalization-test'))
111 test('extract test', function (t) {
112 var extract = tar.Extract(target)
113 var inp = fs.createReadStream(file)
117 extract.on('end', function () {
118 t.equal(ee, expectEntries.length, 'should see ' + expectEntries.length + ' entries')
120 // should get no more entries after end
121 extract.removeAllListeners('entry')
122 extract.on('entry', function (e) {
123 t.fail('Should not get entries after end!')
129 extract.on('entry', function (entry) {
130 var mode = entry.props.mode & (~parseInt('22', 8))
133 mode: mode.toString(8),
134 type: entry.props.type,
135 linkpath: entry.props.linkpath,
138 var wanted = expectEntries[ee++]
139 t.equivalent(found, wanted, 'tar entry ' + ee + ' ' + (wanted && wanted.path))
143 var r = fstream.Reader({
149 r.on('ready', function () {
155 function foundEntry (entry) {
156 var p = entry.path.substr(target.length)
157 var mode = entry.props.mode & (~parseInt('22', 8))
160 mode: mode.toString(8),
161 type: entry.props.type,
162 depth: entry.props.depth,
163 linkpath: entry.props.linkpath
166 var wanted = expectFiles[ef++]
167 t.equivalent(found, wanted, 'unpacked file ' + ef + ' ' + (wanted && wanted.path))
169 entry.on('entry', foundEntry)
173 t.equal(ef, expectFiles.length, 'should have ' + ef + ' items')