1 // Set the umask, so that it works the same everywhere.
2 process.umask(parseInt('22', 8))
4 var tap = require("tap")
5 , tar = require("../tar.js")
7 , path = require("path")
8 , file = path.resolve(__dirname, "fixtures/c.tar")
9 , target = path.resolve(__dirname, "tmp/extract-test")
11 , fstream = require("fstream")
33 { path: 'r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc',
60 { path: '200ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc',
69 { path: '200ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc',
78 { path: '200LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL',
83 linkpath: '200ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc',
96 { path: '200ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc',
101 linkpath: path.resolve(target, '200-hard'),
112 linkpath: undefined },
120 { path: '/200LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL',
122 type: 'SymbolicLink',
125 linkpath: '200ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc',
127 { path: '/200ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc',
132 linkpath: path.join(target, '200-hard'),
152 linkpath: undefined },
157 linkpath: undefined },
162 linkpath: undefined },
167 linkpath: undefined },
168 { path: '/r/e/a/l/l',
172 linkpath: undefined },
173 { path: '/r/e/a/l/l/y',
177 linkpath: undefined },
178 { path: '/r/e/a/l/l/y/-',
182 linkpath: undefined },
183 { path: '/r/e/a/l/l/y/-/d',
187 linkpath: undefined },
188 { path: '/r/e/a/l/l/y/-/d/e',
192 linkpath: undefined },
193 { path: '/r/e/a/l/l/y/-/d/e/e',
197 linkpath: undefined },
198 { path: '/r/e/a/l/l/y/-/d/e/e/p',
202 linkpath: undefined },
203 { path: '/r/e/a/l/l/y/-/d/e/e/p/-',
207 linkpath: undefined },
208 { path: '/r/e/a/l/l/y/-/d/e/e/p/-/f',
212 linkpath: undefined },
213 { path: '/r/e/a/l/l/y/-/d/e/e/p/-/f/o',
217 linkpath: undefined },
218 { path: '/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l',
222 linkpath: undefined },
223 { path: '/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d',
227 linkpath: undefined },
228 { path: '/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e',
232 linkpath: undefined },
233 { path: '/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r',
237 linkpath: undefined },
238 { path: '/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-',
242 linkpath: undefined },
243 { path: '/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p',
247 linkpath: undefined },
248 { path: '/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a',
252 linkpath: undefined },
253 { path: '/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t',
257 linkpath: undefined },
258 { path: '/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h',
262 linkpath: undefined },
263 { path: '/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc',
280 // The extract class basically just pipes the input
281 // to a Reader, and then to a fstream.DirWriter
283 // So, this is as much a test of fstream.Reader and fstream.Writer
284 // as it is of tar.Extract, but it sort of makes sense.
286 tap.test("preclean", function (t) {
287 require("rimraf").sync(__dirname + "/tmp/extract-test")
292 tap.test("extract test", function (t) {
293 var extract = tar.Extract(target)
294 var inp = fs.createReadStream(file)
296 // give it a weird buffer size to try to break in odd places
297 inp.bufferSize = 1234
301 extract.on("end", function () {
302 t.equal(ee, expectEntries.length, "should see "+ee+" entries")
304 // should get no more entries after end
305 extract.removeAllListeners("entry")
306 extract.on("entry", function (e) {
307 t.fail("Should not get entries after end!")
313 extract.on("entry", function (entry) {
316 , mode: entry.props.mode.toString(8)
317 , type: entry.props.type
318 , depth: entry.props.depth
319 , size: entry.props.size
320 , linkpath: entry.props.linkpath
321 , nlink: entry.props.nlink
322 , dev: entry.props.dev
323 , ino: entry.props.ino
326 var wanted = expectEntries[ee ++]
328 t.equivalent(found, wanted, "tar entry " + ee + " " + wanted.path)
332 var r = fstream.Reader({ path: target
334 // this is just to encourage consistency
337 r.on("ready", function () {
343 function foundEntry (entry) {
344 var p = entry.path.substr(target.length)
347 , mode: entry.props.mode.toString(8)
348 , type: entry.props.type
349 , depth: entry.props.depth
350 , size: entry.props.size
351 , linkpath: entry.props.linkpath
352 , nlink: entry.props.nlink
355 var wanted = expectFiles[ef ++]
357 t.has(found, wanted, "unpacked file " + ef + " " + wanted.path)
359 entry.on("entry", foundEntry)
363 t.equal(ef, expectFiles.length, "should have "+ef+" items")