1 // This is exactly like test/pack.js, except that it's excluding
2 // any proprietary headers.
4 // This loses some information about the filesystem, but creates
5 // tarballs that are supported by more versions of tar, especially
6 // old non-spec-compliant copies of gnutar.
8 // the symlink file is excluded from git, because it makes
9 // windows freak the hell out.
10 var fs = require("fs")
11 , path = require("path")
12 , symlink = path.resolve(__dirname, "fixtures/symlink")
13 try { fs.unlinkSync(symlink) } catch (e) {}
14 fs.symlinkSync("./hardlink-1", symlink)
15 process.on("exit", function () {
16 fs.unlinkSync(symlink)
19 var tap = require("tap")
20 , tar = require("../tar.js")
21 , pkg = require("../package.json")
23 , fstream = require("fstream")
24 , Reader = fstream.Reader
25 , Writer = fstream.Writer
26 , input = path.resolve(__dirname, "fixtures/")
27 , target = path.resolve(__dirname, "tmp/pack.tar")
28 , uid = process.getuid ? process.getuid() : 0
29 , gid = process.getgid ? process.getgid() : 0
33 // the global header and root fixtures/ dir are going to get
34 // a different date each time, so omit that bit.
35 // Also, dev/ino values differ across machines, so that's not
54 { path: 'PaxHeader/fixtures/200cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc',
67 { path: 'fixtures/200ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc',
73 { path: 'fixtures/200ccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc',
89 { path: 'fixtures/a.txt',
105 { path: 'fixtures/b.txt',
112 ustar: 'ustar\u0000',
121 { path: 'fixtures/c.txt',
128 ustar: 'ustar\u0000',
137 { path: 'fixtures/cc.txt',
144 ustar: 'ustar\u0000',
153 { path: 'fixtures/dir/',
160 ustar: 'ustar\u0000',
169 { path: 'fixtures/dir/sub/',
176 ustar: 'ustar\u0000',
185 { path: 'fixtures/foo.js',
192 ustar: 'ustar\u0000',
201 { path: 'fixtures/hardlink-1',
208 ustar: 'ustar\u0000',
217 { path: 'fixtures/hardlink-2',
223 linkpath: 'fixtures/hardlink-1',
224 ustar: 'ustar\u0000',
233 { path: 'fixtures/omega.txt',
240 ustar: 'ustar\u0000',
249 { path: 'fixtures/packtest/',
256 ustar: 'ustar\u0000',
265 { path: 'fixtures/packtest/omega.txt',
272 ustar: 'ustar\u0000',
281 { path: 'fixtures/packtest/star.4.html',
288 ustar: 'ustar\u0000',
296 , [ 'extendedHeader',
297 { path: 'PaxHeader/fixtures/packtest/Ω.txt',
303 ustar: 'ustar\u0000',
310 { path: 'fixtures/packtest/Ω.txt',
316 { path: 'fixtures/packtest/Ω.txt',
323 ustar: 'ustar\u0000',
332 { path: 'fixtures/r/',
339 ustar: 'ustar\u0000',
348 { path: 'fixtures/r/e/',
355 ustar: 'ustar\u0000',
364 { path: 'fixtures/r/e/a/',
371 ustar: 'ustar\u0000',
380 { path: 'fixtures/r/e/a/l/',
387 ustar: 'ustar\u0000',
396 { path: 'fixtures/r/e/a/l/l/',
403 ustar: 'ustar\u0000',
412 { path: 'fixtures/r/e/a/l/l/y/',
419 ustar: 'ustar\u0000',
428 { path: 'fixtures/r/e/a/l/l/y/-/',
435 ustar: 'ustar\u0000',
444 { path: 'fixtures/r/e/a/l/l/y/-/d/',
451 ustar: 'ustar\u0000',
460 { path: 'fixtures/r/e/a/l/l/y/-/d/e/',
467 ustar: 'ustar\u0000',
476 { path: 'fixtures/r/e/a/l/l/y/-/d/e/e/',
483 ustar: 'ustar\u0000',
492 { path: 'fixtures/r/e/a/l/l/y/-/d/e/e/p/',
499 ustar: 'ustar\u0000',
508 { path: 'fixtures/r/e/a/l/l/y/-/d/e/e/p/-/',
515 ustar: 'ustar\u0000',
524 { path: 'fixtures/r/e/a/l/l/y/-/d/e/e/p/-/f/',
531 ustar: 'ustar\u0000',
540 { path: 'fixtures/r/e/a/l/l/y/-/d/e/e/p/-/f/o/',
547 ustar: 'ustar\u0000',
556 { path: 'fixtures/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/',
563 ustar: 'ustar\u0000',
572 { path: 'fixtures/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/',
579 ustar: 'ustar\u0000',
588 { path: 'fixtures/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/',
595 ustar: 'ustar\u0000',
604 { path: 'fixtures/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/',
611 ustar: 'ustar\u0000',
620 { path: 'fixtures/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/',
627 ustar: 'ustar\u0000',
636 { path: 'fixtures/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/',
643 ustar: 'ustar\u0000',
652 { path: 'fixtures/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/',
659 ustar: 'ustar\u0000',
668 { path: 'fixtures/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/',
675 ustar: 'ustar\u0000',
684 { path: 'fixtures/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/',
691 ustar: 'ustar\u0000',
700 { path: 'fixtures/r/e/a/l/l/y/-/d/e/e/p/-/f/o/l/d/e/r/-/p/a/t/h/cccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccc',
707 ustar: 'ustar\u0000',
716 { path: 'fixtures/symlink',
721 linkpath: 'hardlink-1',
722 ustar: 'ustar\u0000',
730 , [ 'extendedHeader',
731 { path: 'PaxHeader/fixtures/Ω.txt',
737 ustar: 'ustar\u0000',
744 { path: "fixtures/Ω.txt"
750 { path: 'fixtures/Ω.txt',
757 ustar: 'ustar\u0000',
767 // first, make sure that the hardlinks are actually hardlinks, or this
768 // won't work. Git has a way of replacing them with a copy.
769 var hard1 = path.resolve(__dirname, "fixtures/hardlink-1")
770 , hard2 = path.resolve(__dirname, "fixtures/hardlink-2")
773 try { fs.unlinkSync(hard2) } catch (e) {}
774 fs.linkSync(hard1, hard2)
776 tap.test("with global header", { timeout: 10000 }, function (t) {
780 tap.test("without global header", { timeout: 10000 }, function (t) {
784 function alphasort (a, b) {
786 : a.toLowerCase() > b.toLowerCase() ? 1
787 : a.toLowerCase() < b.toLowerCase() ? -1
793 function runTest (t, doGH) {
794 var reader = Reader({ path: input
795 , filter: function () {
796 return !this.path.match(/\.(tar|hex)$/)
801 var props = doGH ? pkg : {}
802 props.noProprietary = true
803 var pack = Pack(props)
804 var writer = Writer(target)
806 // global header should be skipped regardless, since it has no content.
809 t.ok(reader, "reader ok")
810 t.ok(pack, "pack ok")
811 t.ok(writer, "writer ok")
815 var parse = tar.Parse()
816 t.ok(parse, "parser should be ok")
818 pack.on("data", function (c) {
819 // console.error("PACK DATA")
820 if (c.length !== 512) {
821 // this one is too noisy, only assert if it'll be relevant
822 t.equal(c.length, 512, "parser should emit data in 512byte blocks")
827 pack.on("end", function () {
828 // console.error("PACK END")
829 t.pass("parser ends")
833 pack.on("error", function (er) {
834 t.fail("pack error", er)
837 parse.on("error", function (er) {
838 t.fail("parse error", er)
841 writer.on("error", function (er) {
842 t.fail("writer error", er)
845 reader.on("error", function (er) {
846 t.fail("reader error", er)
849 parse.on("*", function (ev, e) {
850 var wanted = entries[entry++]
852 t.fail("unexpected event: "+ev)
855 t.equal(ev, wanted[0], "event type should be "+wanted[0])
857 if (ev !== wanted[0] || e.path !== wanted[1].path) {
858 console.error("wanted", wanted)
859 console.error([ev, e.props])
860 e.on("end", function () {
861 console.error(e.fields)
866 t.has(e.props, wanted[1], "properties "+wanted[1].path)
868 e.on("end", function () {
870 t.ok(e.fields, "should get fields")
872 t.has(e.fields, wanted[2], "should get expected fields")
880 writer.on("close", function () {
881 t.equal(entry, entries.length, "should get all expected entries")
882 t.pass("it finished")