| author | |
| committer | |
| log | a75fd4ff156abdd131c2b609b9b19573813838a0 |
| tree | 1873447b9f63491eca7e4df2ccf2b08f33064d7e |
| parent | f8e42d6b308a2e523d6a32669d0a021a56f70524 |
Create std/tar/test.zig for test which uses cases from testdata.58 files changed, 377 insertions(+), 370 deletions(-)
lib/std/tar.zig+4-370| ... | @@ -601,376 +601,6 @@ test "tar stripComponents" { | ... | @@ -601,376 +601,6 @@ test "tar stripComponents" { |
| 601 | try expectEqualStrings("c", try stripComponents("a/b/c", 2)); | 601 | try expectEqualStrings("c", try stripComponents("a/b/c", 2)); |
| 602 | } | 602 | } |
| 603 | 603 | ||
| 604 | test "tar run Go test cases" { | ||
| 605 | const Case = struct { | ||
| 606 | const File = struct { | ||
| 607 | name: []const u8, | ||
| 608 | size: usize = 0, | ||
| 609 | mode: u32 = 0, | ||
| 610 | link_name: []const u8 = &[0]u8{}, | ||
| 611 | kind: Header.Kind = .normal, | ||
| 612 | truncated: bool = false, // when there is no file body, just header, usefull for huge files | ||
| 613 | }; | ||
| 614 | |||
| 615 | path: []const u8, // path to the tar archive file on dis | ||
| 616 | files: []const File = &[_]@This().File{}, // expected files to found in archive | ||
| 617 | chksums: []const []const u8 = &[_][]const u8{}, // chksums of files content | ||
| 618 | err: ?anyerror = null, // parsing should fail with this error | ||
| 619 | }; | ||
| 620 | |||
| 621 | const src_path = comptime std.fs.path.dirname(@src().file) orelse "."; | ||
| 622 | const test_dir = try std.fs.cwd().openDir(src_path ++ "/../../test/cases/tar", .{}); | ||
| 623 | |||
| 624 | const cases = [_]Case{ | ||
| 625 | .{ | ||
| 626 | .path = "gnu.tar", | ||
| 627 | .files = &[_]Case.File{ | ||
| 628 | .{ | ||
| 629 | .name = "small.txt", | ||
| 630 | .size = 5, | ||
| 631 | .mode = 0o640, | ||
| 632 | }, | ||
| 633 | .{ | ||
| 634 | .name = "small2.txt", | ||
| 635 | .size = 11, | ||
| 636 | .mode = 0o640, | ||
| 637 | }, | ||
| 638 | }, | ||
| 639 | .chksums = &[_][]const u8{ | ||
| 640 | "e38b27eaccb4391bdec553a7f3ae6b2f", | ||
| 641 | "c65bd2e50a56a2138bf1716f2fd56fe9", | ||
| 642 | }, | ||
| 643 | }, | ||
| 644 | .{ | ||
| 645 | .path = "sparse-formats.tar", | ||
| 646 | .err = error.TarUnsupportedHeader, | ||
| 647 | }, | ||
| 648 | .{ | ||
| 649 | .path = "star.tar", | ||
| 650 | .files = &[_]Case.File{ | ||
| 651 | .{ | ||
| 652 | .name = "small.txt", | ||
| 653 | .size = 5, | ||
| 654 | .mode = 0o640, | ||
| 655 | }, | ||
| 656 | .{ | ||
| 657 | .name = "small2.txt", | ||
| 658 | .size = 11, | ||
| 659 | .mode = 0o640, | ||
| 660 | }, | ||
| 661 | }, | ||
| 662 | .chksums = &[_][]const u8{ | ||
| 663 | "e38b27eaccb4391bdec553a7f3ae6b2f", | ||
| 664 | "c65bd2e50a56a2138bf1716f2fd56fe9", | ||
| 665 | }, | ||
| 666 | }, | ||
| 667 | .{ | ||
| 668 | .path = "v7.tar", | ||
| 669 | .files = &[_]Case.File{ | ||
| 670 | .{ | ||
| 671 | .name = "small.txt", | ||
| 672 | .size = 5, | ||
| 673 | .mode = 0o444, | ||
| 674 | }, | ||
| 675 | .{ | ||
| 676 | .name = "small2.txt", | ||
| 677 | .size = 11, | ||
| 678 | .mode = 0o444, | ||
| 679 | }, | ||
| 680 | }, | ||
| 681 | .chksums = &[_][]const u8{ | ||
| 682 | "e38b27eaccb4391bdec553a7f3ae6b2f", | ||
| 683 | "c65bd2e50a56a2138bf1716f2fd56fe9", | ||
| 684 | }, | ||
| 685 | }, | ||
| 686 | .{ | ||
| 687 | .path = "pax.tar", | ||
| 688 | .files = &[_]Case.File{ | ||
| 689 | .{ | ||
| 690 | .name = "a/123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100", | ||
| 691 | .size = 7, | ||
| 692 | .mode = 0o664, | ||
| 693 | }, | ||
| 694 | .{ | ||
| 695 | .name = "a/b", | ||
| 696 | .size = 0, | ||
| 697 | .kind = .symbolic_link, | ||
| 698 | .mode = 0o777, | ||
| 699 | .link_name = "123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100", | ||
| 700 | }, | ||
| 701 | }, | ||
| 702 | .chksums = &[_][]const u8{ | ||
| 703 | "3c382e8f5b6631aa2db52643912ffd4a", | ||
| 704 | }, | ||
| 705 | }, | ||
| 706 | .{ | ||
| 707 | // pax attribute don't end with \n | ||
| 708 | .path = "pax-bad-hdr-file.tar", | ||
| 709 | .err = error.PaxInvalidAttributeEnd, | ||
| 710 | }, | ||
| 711 | .{ | ||
| 712 | // size is in pax attribute | ||
| 713 | .path = "pax-pos-size-file.tar", | ||
| 714 | .files = &[_]Case.File{ | ||
| 715 | .{ | ||
| 716 | .name = "foo", | ||
| 717 | .size = 999, | ||
| 718 | .kind = .normal, | ||
| 719 | .mode = 0o640, | ||
| 720 | }, | ||
| 721 | }, | ||
| 722 | .chksums = &[_][]const u8{ | ||
| 723 | "0afb597b283fe61b5d4879669a350556", | ||
| 724 | }, | ||
| 725 | }, | ||
| 726 | .{ | ||
| 727 | // has pax records which we are not interested in | ||
| 728 | .path = "pax-records.tar", | ||
| 729 | .files = &[_]Case.File{ | ||
| 730 | .{ | ||
| 731 | .name = "file", | ||
| 732 | }, | ||
| 733 | }, | ||
| 734 | }, | ||
| 735 | .{ | ||
| 736 | // has global records which we are ignoring | ||
| 737 | .path = "pax-global-records.tar", | ||
| 738 | .files = &[_]Case.File{ | ||
| 739 | .{ | ||
| 740 | .name = "file1", | ||
| 741 | }, | ||
| 742 | .{ | ||
| 743 | .name = "file2", | ||
| 744 | }, | ||
| 745 | .{ | ||
| 746 | .name = "file3", | ||
| 747 | }, | ||
| 748 | .{ | ||
| 749 | .name = "file4", | ||
| 750 | }, | ||
| 751 | }, | ||
| 752 | }, | ||
| 753 | .{ | ||
| 754 | .path = "nil-uid.tar", | ||
| 755 | .files = &[_]Case.File{ | ||
| 756 | .{ | ||
| 757 | .name = "P1050238.JPG.log", | ||
| 758 | .size = 14, | ||
| 759 | .kind = .normal, | ||
| 760 | .mode = 0o664, | ||
| 761 | }, | ||
| 762 | }, | ||
| 763 | .chksums = &[_][]const u8{ | ||
| 764 | "08d504674115e77a67244beac19668f5", | ||
| 765 | }, | ||
| 766 | }, | ||
| 767 | .{ | ||
| 768 | // has xattrs and pax records which we are ignoring | ||
| 769 | .path = "xattrs.tar", | ||
| 770 | .files = &[_]Case.File{ | ||
| 771 | .{ | ||
| 772 | .name = "small.txt", | ||
| 773 | .size = 5, | ||
| 774 | .kind = .normal, | ||
| 775 | .mode = 0o644, | ||
| 776 | }, | ||
| 777 | .{ | ||
| 778 | .name = "small2.txt", | ||
| 779 | .size = 11, | ||
| 780 | .kind = .normal, | ||
| 781 | .mode = 0o644, | ||
| 782 | }, | ||
| 783 | }, | ||
| 784 | .chksums = &[_][]const u8{ | ||
| 785 | "e38b27eaccb4391bdec553a7f3ae6b2f", | ||
| 786 | "c65bd2e50a56a2138bf1716f2fd56fe9", | ||
| 787 | }, | ||
| 788 | }, | ||
| 789 | .{ | ||
| 790 | .path = "gnu-multi-hdrs.tar", | ||
| 791 | .files = &[_]Case.File{ | ||
| 792 | .{ | ||
| 793 | .name = "GNU2/GNU2/long-path-name", | ||
| 794 | .link_name = "GNU4/GNU4/long-linkpath-name", | ||
| 795 | .kind = .symbolic_link, | ||
| 796 | }, | ||
| 797 | }, | ||
| 798 | }, | ||
| 799 | .{ | ||
| 800 | // has gnu type D (directory) and S (sparse) blocks | ||
| 801 | .path = "gnu-incremental.tar", | ||
| 802 | .err = error.TarUnsupportedHeader, | ||
| 803 | }, | ||
| 804 | .{ | ||
| 805 | // should use values only from last pax header | ||
| 806 | .path = "pax-multi-hdrs.tar", | ||
| 807 | .files = &[_]Case.File{ | ||
| 808 | .{ | ||
| 809 | .name = "bar", | ||
| 810 | .link_name = "PAX4/PAX4/long-linkpath-name", | ||
| 811 | .kind = .symbolic_link, | ||
| 812 | }, | ||
| 813 | }, | ||
| 814 | }, | ||
| 815 | .{ | ||
| 816 | .path = "gnu-long-nul.tar", | ||
| 817 | .files = &[_]Case.File{ | ||
| 818 | .{ | ||
| 819 | .name = "0123456789", | ||
| 820 | .mode = 0o644, | ||
| 821 | }, | ||
| 822 | }, | ||
| 823 | }, | ||
| 824 | .{ | ||
| 825 | .path = "gnu-utf8.tar", | ||
| 826 | .files = &[_]Case.File{ | ||
| 827 | .{ | ||
| 828 | .name = "☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹", | ||
| 829 | .mode = 0o644, | ||
| 830 | }, | ||
| 831 | }, | ||
| 832 | }, | ||
| 833 | .{ | ||
| 834 | .path = "gnu-not-utf8.tar", | ||
| 835 | .files = &[_]Case.File{ | ||
| 836 | .{ | ||
| 837 | .name = "hi\x80\x81\x82\x83bye", | ||
| 838 | .mode = 0o644, | ||
| 839 | }, | ||
| 840 | }, | ||
| 841 | }, | ||
| 842 | .{ | ||
| 843 | // null in pax key | ||
| 844 | .path = "pax-nul-xattrs.tar", | ||
| 845 | .err = error.PaxNullInKeyword, | ||
| 846 | }, | ||
| 847 | .{ | ||
| 848 | .path = "pax-nul-path.tar", | ||
| 849 | .err = error.PaxNullInValue, | ||
| 850 | }, | ||
| 851 | .{ | ||
| 852 | .path = "neg-size.tar", | ||
| 853 | .err = error.TarHeader, | ||
| 854 | }, | ||
| 855 | .{ | ||
| 856 | .path = "issue10968.tar", | ||
| 857 | .err = error.TarHeader, | ||
| 858 | }, | ||
| 859 | .{ | ||
| 860 | .path = "issue11169.tar", | ||
| 861 | .err = error.TarHeader, | ||
| 862 | }, | ||
| 863 | .{ | ||
| 864 | .path = "issue12435.tar", | ||
| 865 | .err = error.TarHeaderChksum, | ||
| 866 | }, | ||
| 867 | .{ | ||
| 868 | // has magic with space at end instead of null | ||
| 869 | .path = "invalid-go17.tar", | ||
| 870 | .files = &[_]Case.File{ | ||
| 871 | .{ | ||
| 872 | .name = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/foo", | ||
| 873 | }, | ||
| 874 | }, | ||
| 875 | }, | ||
| 876 | .{ | ||
| 877 | .path = "ustar-file-devs.tar", | ||
| 878 | .files = &[_]Case.File{ | ||
| 879 | .{ | ||
| 880 | .name = "file", | ||
| 881 | .mode = 0o644, | ||
| 882 | }, | ||
| 883 | }, | ||
| 884 | }, | ||
| 885 | .{ | ||
| 886 | .path = "trailing-slash.tar", | ||
| 887 | .files = &[_]Case.File{ | ||
| 888 | .{ | ||
| 889 | .name = "123456789/" ** 30, | ||
| 890 | .kind = .directory, | ||
| 891 | }, | ||
| 892 | }, | ||
| 893 | }, | ||
| 894 | .{ | ||
| 895 | // Has size in gnu extended format. To represent size bigger than 8 GB. | ||
| 896 | .path = "writer-big.tar", | ||
| 897 | .files = &[_]Case.File{ | ||
| 898 | .{ | ||
| 899 | .name = "tmp/16gig.txt", | ||
| 900 | .size = 16 * 1024 * 1024 * 1024, | ||
| 901 | .truncated = true, | ||
| 902 | .mode = 0o640, | ||
| 903 | }, | ||
| 904 | }, | ||
| 905 | }, | ||
| 906 | .{ | ||
| 907 | // Size in gnu extended format, and name in pax attribute. | ||
| 908 | .path = "writer-big-long.tar", | ||
| 909 | .files = &[_]Case.File{ | ||
| 910 | .{ | ||
| 911 | .name = "longname/" ** 15 ++ "16gig.txt", | ||
| 912 | .size = 16 * 1024 * 1024 * 1024, | ||
| 913 | .mode = 0o644, | ||
| 914 | .truncated = true, | ||
| 915 | }, | ||
| 916 | }, | ||
| 917 | }, | ||
| 918 | }; | ||
| 919 | |||
| 920 | for (cases) |case| { | ||
| 921 | var fs_file = try test_dir.openFile(case.path, .{}); | ||
| 922 | |||
| 923 | defer fs_file.close(); | ||
| 924 | |||
| 925 | var iter = tarReader(fs_file.reader(), null); | ||
| 926 | var i: usize = 0; | ||
| 927 | while (iter.next() catch |err| { | ||
| 928 | if (case.err) |e| { | ||
| 929 | try std.testing.expectEqual(e, err); | ||
| 930 | continue; | ||
| 931 | } else { | ||
| 932 | return err; | ||
| 933 | } | ||
| 934 | }) |actual| : (i += 1) { | ||
| 935 | const expected = case.files[i]; | ||
| 936 | try std.testing.expectEqualStrings(expected.name, actual.name); | ||
| 937 | try std.testing.expectEqual(expected.size, actual.size); | ||
| 938 | try std.testing.expectEqual(expected.kind, actual.kind); | ||
| 939 | try std.testing.expectEqual(expected.mode, actual.mode); | ||
| 940 | try std.testing.expectEqualStrings(expected.link_name, actual.link_name); | ||
| 941 | |||
| 942 | if (case.chksums.len > i) { | ||
| 943 | var md5writer = Md5Writer{}; | ||
| 944 | try actual.write(&md5writer); | ||
| 945 | const chksum = md5writer.chksum(); | ||
| 946 | try std.testing.expectEqualStrings(case.chksums[i], &chksum); | ||
| 947 | } else { | ||
| 948 | if (!expected.truncated) try actual.skip(); // skip file content | ||
| 949 | } | ||
| 950 | } | ||
| 951 | try std.testing.expectEqual(case.files.len, i); | ||
| 952 | } | ||
| 953 | } | ||
| 954 | |||
| 955 | // used in test to calculate file chksum | ||
| 956 | const Md5Writer = struct { | ||
| 957 | h: std.crypto.hash.Md5 = std.crypto.hash.Md5.init(.{}), | ||
| 958 | |||
| 959 | pub fn writeAll(self: *Md5Writer, buf: []const u8) !void { | ||
| 960 | self.h.update(buf); | ||
| 961 | } | ||
| 962 | |||
| 963 | pub fn writeByte(self: *Md5Writer, byte: u8) !void { | ||
| 964 | self.h.update(&[_]u8{byte}); | ||
| 965 | } | ||
| 966 | |||
| 967 | pub fn chksum(self: *Md5Writer) [32]u8 { | ||
| 968 | var s = [_]u8{0} ** 16; | ||
| 969 | self.h.final(&s); | ||
| 970 | return std.fmt.bytesToHex(s, .lower); | ||
| 971 | } | ||
| 972 | }; | ||
| 973 | |||
| 974 | test "tar PaxReader" { | 604 | test "tar PaxReader" { |
| 975 | const Attr = struct { | 605 | const Attr = struct { |
| 976 | kind: PaxAttributeKind, | 606 | kind: PaxAttributeKind, |
| ... | @@ -1094,3 +724,7 @@ test "tar PaxReader" { | ... | @@ -1094,3 +724,7 @@ test "tar PaxReader" { |
| 1094 | try std.testing.expect(case.err == null); | 724 | try std.testing.expect(case.err == null); |
| 1095 | } | 725 | } |
| 1096 | } | 726 | } |
| 727 | |||
| 728 | test { | ||
| 729 | _ = @import("tar/test.zig"); | ||
| 730 | } |
lib/std/tar/test.zig created+373| ... | @@ -0,0 +1,373 @@ | ||
| 1 | const std = @import("../std.zig"); | ||
| 2 | const tar = std.tar; | ||
| 3 | const assert = std.debug.assert; | ||
| 4 | |||
| 5 | test "tar run Go test cases" { | ||
| 6 | const Case = struct { | ||
| 7 | const File = struct { | ||
| 8 | name: []const u8, | ||
| 9 | size: usize = 0, | ||
| 10 | mode: u32 = 0, | ||
| 11 | link_name: []const u8 = &[0]u8{}, | ||
| 12 | kind: tar.Header.Kind = .normal, | ||
| 13 | truncated: bool = false, // when there is no file body, just header, usefull for huge files | ||
| 14 | }; | ||
| 15 | |||
| 16 | path: []const u8, // path to the tar archive file on dis | ||
| 17 | files: []const File = &[_]@This().File{}, // expected files to found in archive | ||
| 18 | chksums: []const []const u8 = &[_][]const u8{}, // chksums of files content | ||
| 19 | err: ?anyerror = null, // parsing should fail with this error | ||
| 20 | }; | ||
| 21 | |||
| 22 | const src_path = comptime std.fs.path.dirname(@src().file) orelse "."; | ||
| 23 | const test_dir = try std.fs.cwd().openDir(src_path ++ "/testdata", .{}); | ||
| 24 | |||
| 25 | const cases = [_]Case{ | ||
| 26 | .{ | ||
| 27 | .path = "gnu.tar", | ||
| 28 | .files = &[_]Case.File{ | ||
| 29 | .{ | ||
| 30 | .name = "small.txt", | ||
| 31 | .size = 5, | ||
| 32 | .mode = 0o640, | ||
| 33 | }, | ||
| 34 | .{ | ||
| 35 | .name = "small2.txt", | ||
| 36 | .size = 11, | ||
| 37 | .mode = 0o640, | ||
| 38 | }, | ||
| 39 | }, | ||
| 40 | .chksums = &[_][]const u8{ | ||
| 41 | "e38b27eaccb4391bdec553a7f3ae6b2f", | ||
| 42 | "c65bd2e50a56a2138bf1716f2fd56fe9", | ||
| 43 | }, | ||
| 44 | }, | ||
| 45 | .{ | ||
| 46 | .path = "sparse-formats.tar", | ||
| 47 | .err = error.TarUnsupportedHeader, | ||
| 48 | }, | ||
| 49 | .{ | ||
| 50 | .path = "star.tar", | ||
| 51 | .files = &[_]Case.File{ | ||
| 52 | .{ | ||
| 53 | .name = "small.txt", | ||
| 54 | .size = 5, | ||
| 55 | .mode = 0o640, | ||
| 56 | }, | ||
| 57 | .{ | ||
| 58 | .name = "small2.txt", | ||
| 59 | .size = 11, | ||
| 60 | .mode = 0o640, | ||
| 61 | }, | ||
| 62 | }, | ||
| 63 | .chksums = &[_][]const u8{ | ||
| 64 | "e38b27eaccb4391bdec553a7f3ae6b2f", | ||
| 65 | "c65bd2e50a56a2138bf1716f2fd56fe9", | ||
| 66 | }, | ||
| 67 | }, | ||
| 68 | .{ | ||
| 69 | .path = "v7.tar", | ||
| 70 | .files = &[_]Case.File{ | ||
| 71 | .{ | ||
| 72 | .name = "small.txt", | ||
| 73 | .size = 5, | ||
| 74 | .mode = 0o444, | ||
| 75 | }, | ||
| 76 | .{ | ||
| 77 | .name = "small2.txt", | ||
| 78 | .size = 11, | ||
| 79 | .mode = 0o444, | ||
| 80 | }, | ||
| 81 | }, | ||
| 82 | .chksums = &[_][]const u8{ | ||
| 83 | "e38b27eaccb4391bdec553a7f3ae6b2f", | ||
| 84 | "c65bd2e50a56a2138bf1716f2fd56fe9", | ||
| 85 | }, | ||
| 86 | }, | ||
| 87 | .{ | ||
| 88 | .path = "pax.tar", | ||
| 89 | .files = &[_]Case.File{ | ||
| 90 | .{ | ||
| 91 | .name = "a/123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100", | ||
| 92 | .size = 7, | ||
| 93 | .mode = 0o664, | ||
| 94 | }, | ||
| 95 | .{ | ||
| 96 | .name = "a/b", | ||
| 97 | .size = 0, | ||
| 98 | .kind = .symbolic_link, | ||
| 99 | .mode = 0o777, | ||
| 100 | .link_name = "123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100", | ||
| 101 | }, | ||
| 102 | }, | ||
| 103 | .chksums = &[_][]const u8{ | ||
| 104 | "3c382e8f5b6631aa2db52643912ffd4a", | ||
| 105 | }, | ||
| 106 | }, | ||
| 107 | .{ | ||
| 108 | // pax attribute don't end with \n | ||
| 109 | .path = "pax-bad-hdr-file.tar", | ||
| 110 | .err = error.PaxInvalidAttributeEnd, | ||
| 111 | }, | ||
| 112 | .{ | ||
| 113 | // size is in pax attribute | ||
| 114 | .path = "pax-pos-size-file.tar", | ||
| 115 | .files = &[_]Case.File{ | ||
| 116 | .{ | ||
| 117 | .name = "foo", | ||
| 118 | .size = 999, | ||
| 119 | .kind = .normal, | ||
| 120 | .mode = 0o640, | ||
| 121 | }, | ||
| 122 | }, | ||
| 123 | .chksums = &[_][]const u8{ | ||
| 124 | "0afb597b283fe61b5d4879669a350556", | ||
| 125 | }, | ||
| 126 | }, | ||
| 127 | .{ | ||
| 128 | // has pax records which we are not interested in | ||
| 129 | .path = "pax-records.tar", | ||
| 130 | .files = &[_]Case.File{ | ||
| 131 | .{ | ||
| 132 | .name = "file", | ||
| 133 | }, | ||
| 134 | }, | ||
| 135 | }, | ||
| 136 | .{ | ||
| 137 | // has global records which we are ignoring | ||
| 138 | .path = "pax-global-records.tar", | ||
| 139 | .files = &[_]Case.File{ | ||
| 140 | .{ | ||
| 141 | .name = "file1", | ||
| 142 | }, | ||
| 143 | .{ | ||
| 144 | .name = "file2", | ||
| 145 | }, | ||
| 146 | .{ | ||
| 147 | .name = "file3", | ||
| 148 | }, | ||
| 149 | .{ | ||
| 150 | .name = "file4", | ||
| 151 | }, | ||
| 152 | }, | ||
| 153 | }, | ||
| 154 | .{ | ||
| 155 | .path = "nil-uid.tar", | ||
| 156 | .files = &[_]Case.File{ | ||
| 157 | .{ | ||
| 158 | .name = "P1050238.JPG.log", | ||
| 159 | .size = 14, | ||
| 160 | .kind = .normal, | ||
| 161 | .mode = 0o664, | ||
| 162 | }, | ||
| 163 | }, | ||
| 164 | .chksums = &[_][]const u8{ | ||
| 165 | "08d504674115e77a67244beac19668f5", | ||
| 166 | }, | ||
| 167 | }, | ||
| 168 | .{ | ||
| 169 | // has xattrs and pax records which we are ignoring | ||
| 170 | .path = "xattrs.tar", | ||
| 171 | .files = &[_]Case.File{ | ||
| 172 | .{ | ||
| 173 | .name = "small.txt", | ||
| 174 | .size = 5, | ||
| 175 | .kind = .normal, | ||
| 176 | .mode = 0o644, | ||
| 177 | }, | ||
| 178 | .{ | ||
| 179 | .name = "small2.txt", | ||
| 180 | .size = 11, | ||
| 181 | .kind = .normal, | ||
| 182 | .mode = 0o644, | ||
| 183 | }, | ||
| 184 | }, | ||
| 185 | .chksums = &[_][]const u8{ | ||
| 186 | "e38b27eaccb4391bdec553a7f3ae6b2f", | ||
| 187 | "c65bd2e50a56a2138bf1716f2fd56fe9", | ||
| 188 | }, | ||
| 189 | }, | ||
| 190 | .{ | ||
| 191 | .path = "gnu-multi-hdrs.tar", | ||
| 192 | .files = &[_]Case.File{ | ||
| 193 | .{ | ||
| 194 | .name = "GNU2/GNU2/long-path-name", | ||
| 195 | .link_name = "GNU4/GNU4/long-linkpath-name", | ||
| 196 | .kind = .symbolic_link, | ||
| 197 | }, | ||
| 198 | }, | ||
| 199 | }, | ||
| 200 | .{ | ||
| 201 | // has gnu type D (directory) and S (sparse) blocks | ||
| 202 | .path = "gnu-incremental.tar", | ||
| 203 | .err = error.TarUnsupportedHeader, | ||
| 204 | }, | ||
| 205 | .{ | ||
| 206 | // should use values only from last pax header | ||
| 207 | .path = "pax-multi-hdrs.tar", | ||
| 208 | .files = &[_]Case.File{ | ||
| 209 | .{ | ||
| 210 | .name = "bar", | ||
| 211 | .link_name = "PAX4/PAX4/long-linkpath-name", | ||
| 212 | .kind = .symbolic_link, | ||
| 213 | }, | ||
| 214 | }, | ||
| 215 | }, | ||
| 216 | .{ | ||
| 217 | .path = "gnu-long-nul.tar", | ||
| 218 | .files = &[_]Case.File{ | ||
| 219 | .{ | ||
| 220 | .name = "0123456789", | ||
| 221 | .mode = 0o644, | ||
| 222 | }, | ||
| 223 | }, | ||
| 224 | }, | ||
| 225 | .{ | ||
| 226 | .path = "gnu-utf8.tar", | ||
| 227 | .files = &[_]Case.File{ | ||
| 228 | .{ | ||
| 229 | .name = "☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹☺☻☹", | ||
| 230 | .mode = 0o644, | ||
| 231 | }, | ||
| 232 | }, | ||
| 233 | }, | ||
| 234 | .{ | ||
| 235 | .path = "gnu-not-utf8.tar", | ||
| 236 | .files = &[_]Case.File{ | ||
| 237 | .{ | ||
| 238 | .name = "hi\x80\x81\x82\x83bye", | ||
| 239 | .mode = 0o644, | ||
| 240 | }, | ||
| 241 | }, | ||
| 242 | }, | ||
| 243 | .{ | ||
| 244 | // null in pax key | ||
| 245 | .path = "pax-nul-xattrs.tar", | ||
| 246 | .err = error.PaxNullInKeyword, | ||
| 247 | }, | ||
| 248 | .{ | ||
| 249 | .path = "pax-nul-path.tar", | ||
| 250 | .err = error.PaxNullInValue, | ||
| 251 | }, | ||
| 252 | .{ | ||
| 253 | .path = "neg-size.tar", | ||
| 254 | .err = error.TarHeader, | ||
| 255 | }, | ||
| 256 | .{ | ||
| 257 | .path = "issue10968.tar", | ||
| 258 | .err = error.TarHeader, | ||
| 259 | }, | ||
| 260 | .{ | ||
| 261 | .path = "issue11169.tar", | ||
| 262 | .err = error.TarHeader, | ||
| 263 | }, | ||
| 264 | .{ | ||
| 265 | .path = "issue12435.tar", | ||
| 266 | .err = error.TarHeaderChksum, | ||
| 267 | }, | ||
| 268 | .{ | ||
| 269 | // has magic with space at end instead of null | ||
| 270 | .path = "invalid-go17.tar", | ||
| 271 | .files = &[_]Case.File{ | ||
| 272 | .{ | ||
| 273 | .name = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/foo", | ||
| 274 | }, | ||
| 275 | }, | ||
| 276 | }, | ||
| 277 | .{ | ||
| 278 | .path = "ustar-file-devs.tar", | ||
| 279 | .files = &[_]Case.File{ | ||
| 280 | .{ | ||
| 281 | .name = "file", | ||
| 282 | .mode = 0o644, | ||
| 283 | }, | ||
| 284 | }, | ||
| 285 | }, | ||
| 286 | .{ | ||
| 287 | .path = "trailing-slash.tar", | ||
| 288 | .files = &[_]Case.File{ | ||
| 289 | .{ | ||
| 290 | .name = "123456789/" ** 30, | ||
| 291 | .kind = .directory, | ||
| 292 | }, | ||
| 293 | }, | ||
| 294 | }, | ||
| 295 | .{ | ||
| 296 | // Has size in gnu extended format. To represent size bigger than 8 GB. | ||
| 297 | .path = "writer-big.tar", | ||
| 298 | .files = &[_]Case.File{ | ||
| 299 | .{ | ||
| 300 | .name = "tmp/16gig.txt", | ||
| 301 | .size = 16 * 1024 * 1024 * 1024, | ||
| 302 | .truncated = true, | ||
| 303 | .mode = 0o640, | ||
| 304 | }, | ||
| 305 | }, | ||
| 306 | }, | ||
| 307 | .{ | ||
| 308 | // Size in gnu extended format, and name in pax attribute. | ||
| 309 | .path = "writer-big-long.tar", | ||
| 310 | .files = &[_]Case.File{ | ||
| 311 | .{ | ||
| 312 | .name = "longname/" ** 15 ++ "16gig.txt", | ||
| 313 | .size = 16 * 1024 * 1024 * 1024, | ||
| 314 | .mode = 0o644, | ||
| 315 | .truncated = true, | ||
| 316 | }, | ||
| 317 | }, | ||
| 318 | }, | ||
| 319 | }; | ||
| 320 | |||
| 321 | for (cases) |case| { | ||
| 322 | var fs_file = try test_dir.openFile(case.path, .{}); | ||
| 323 | |||
| 324 | defer fs_file.close(); | ||
| 325 | |||
| 326 | var iter = tar.tarReader(fs_file.reader(), null); | ||
| 327 | var i: usize = 0; | ||
| 328 | while (iter.next() catch |err| { | ||
| 329 | if (case.err) |e| { | ||
| 330 | try std.testing.expectEqual(e, err); | ||
| 331 | continue; | ||
| 332 | } else { | ||
| 333 | return err; | ||
| 334 | } | ||
| 335 | }) |actual| : (i += 1) { | ||
| 336 | const expected = case.files[i]; | ||
| 337 | try std.testing.expectEqualStrings(expected.name, actual.name); | ||
| 338 | try std.testing.expectEqual(expected.size, actual.size); | ||
| 339 | try std.testing.expectEqual(expected.kind, actual.kind); | ||
| 340 | try std.testing.expectEqual(expected.mode, actual.mode); | ||
| 341 | try std.testing.expectEqualStrings(expected.link_name, actual.link_name); | ||
| 342 | |||
| 343 | if (case.chksums.len > i) { | ||
| 344 | var md5writer = Md5Writer{}; | ||
| 345 | try actual.write(&md5writer); | ||
| 346 | const chksum = md5writer.chksum(); | ||
| 347 | try std.testing.expectEqualStrings(case.chksums[i], &chksum); | ||
| 348 | } else { | ||
| 349 | if (!expected.truncated) try actual.skip(); // skip file content | ||
| 350 | } | ||
| 351 | } | ||
| 352 | try std.testing.expectEqual(case.files.len, i); | ||
| 353 | } | ||
| 354 | } | ||
| 355 | |||
| 356 | // used in test to calculate file chksum | ||
| 357 | const Md5Writer = struct { | ||
| 358 | h: std.crypto.hash.Md5 = std.crypto.hash.Md5.init(.{}), | ||
| 359 | |||
| 360 | pub fn writeAll(self: *Md5Writer, buf: []const u8) !void { | ||
| 361 | self.h.update(buf); | ||
| 362 | } | ||
| 363 | |||
| 364 | pub fn writeByte(self: *Md5Writer, byte: u8) !void { | ||
| 365 | self.h.update(&[_]u8{byte}); | ||
| 366 | } | ||
| 367 | |||
| 368 | pub fn chksum(self: *Md5Writer) [32]u8 { | ||
| 369 | var s = [_]u8{0} ** 16; | ||
| 370 | self.h.final(&s); | ||
| 371 | return std.fmt.bytesToHex(s, .lower); | ||
| 372 | } | ||
| 373 | }; | ||
lib/std/tar/testdata/gnu-incremental.tar created| Binary files /dev/null and b/lib/std/tar/testdata/gnu-incremental.tar differ | |||
lib/std/tar/testdata/gnu-long-nul.tar created| Binary files /dev/null and b/lib/std/tar/testdata/gnu-long-nul.tar differ | |||
lib/std/tar/testdata/gnu-multi-hdrs.tar created| Binary files /dev/null and b/lib/std/tar/testdata/gnu-multi-hdrs.tar differ | |||
lib/std/tar/testdata/gnu-not-utf8.tar created| Binary files /dev/null and b/lib/std/tar/testdata/gnu-not-utf8.tar differ | |||
lib/std/tar/testdata/gnu-utf8.tar created| Binary files /dev/null and b/lib/std/tar/testdata/gnu-utf8.tar differ | |||
lib/std/tar/testdata/gnu.tar created| Binary files /dev/null and b/lib/std/tar/testdata/gnu.tar differ | |||
lib/std/tar/testdata/invalid-go17.tar created| Binary files /dev/null and b/lib/std/tar/testdata/invalid-go17.tar differ | |||
lib/std/tar/testdata/issue10968.tar created| Binary files /dev/null and b/lib/std/tar/testdata/issue10968.tar differ | |||
lib/std/tar/testdata/issue11169.tar created| Binary files /dev/null and b/lib/std/tar/testdata/issue11169.tar differ | |||
lib/std/tar/testdata/issue12435.tar created| Binary files /dev/null and b/lib/std/tar/testdata/issue12435.tar differ | |||
lib/std/tar/testdata/neg-size.tar created| Binary files /dev/null and b/lib/std/tar/testdata/neg-size.tar differ | |||
lib/std/tar/testdata/nil-uid.tar created| Binary files /dev/null and b/lib/std/tar/testdata/nil-uid.tar differ | |||
lib/std/tar/testdata/pax-bad-hdr-file.tar created| Binary files /dev/null and b/lib/std/tar/testdata/pax-bad-hdr-file.tar differ | |||
lib/std/tar/testdata/pax-global-records.tar created| Binary files /dev/null and b/lib/std/tar/testdata/pax-global-records.tar differ | |||
lib/std/tar/testdata/pax-multi-hdrs.tar created| Binary files /dev/null and b/lib/std/tar/testdata/pax-multi-hdrs.tar differ | |||
lib/std/tar/testdata/pax-nul-path.tar created| Binary files /dev/null and b/lib/std/tar/testdata/pax-nul-path.tar differ | |||
lib/std/tar/testdata/pax-nul-xattrs.tar created| Binary files /dev/null and b/lib/std/tar/testdata/pax-nul-xattrs.tar differ | |||
lib/std/tar/testdata/pax-pos-size-file.tar created| Binary files /dev/null and b/lib/std/tar/testdata/pax-pos-size-file.tar differ | |||
lib/std/tar/testdata/pax-records.tar created| Binary files /dev/null and b/lib/std/tar/testdata/pax-records.tar differ | |||
lib/std/tar/testdata/pax.tar created| Binary files /dev/null and b/lib/std/tar/testdata/pax.tar differ | |||
lib/std/tar/testdata/sparse-formats.tar created| Binary files /dev/null and b/lib/std/tar/testdata/sparse-formats.tar differ | |||
lib/std/tar/testdata/star.tar created| Binary files /dev/null and b/lib/std/tar/testdata/star.tar differ | |||
lib/std/tar/testdata/trailing-slash.tar created| Binary files /dev/null and b/lib/std/tar/testdata/trailing-slash.tar differ | |||
lib/std/tar/testdata/ustar-file-devs.tar created| Binary files /dev/null and b/lib/std/tar/testdata/ustar-file-devs.tar differ | |||
lib/std/tar/testdata/v7.tar created| Binary files /dev/null and b/lib/std/tar/testdata/v7.tar differ | |||
lib/std/tar/testdata/writer-big-long.tar created| Binary files /dev/null and b/lib/std/tar/testdata/writer-big-long.tar differ | |||
lib/std/tar/testdata/writer-big.tar created| Binary files /dev/null and b/lib/std/tar/testdata/writer-big.tar differ | |||
lib/std/tar/testdata/xattrs.tar created| Binary files /dev/null and b/lib/std/tar/testdata/xattrs.tar differ | |||
test/cases/tar/gnu-incremental.tar deleted| Binary files a/test/cases/tar/gnu-incremental.tar and /dev/null differ | |||
test/cases/tar/gnu-long-nul.tar deleted| Binary files a/test/cases/tar/gnu-long-nul.tar and /dev/null differ | |||
test/cases/tar/gnu-multi-hdrs.tar deleted| Binary files a/test/cases/tar/gnu-multi-hdrs.tar and /dev/null differ | |||
test/cases/tar/gnu-not-utf8.tar deleted| Binary files a/test/cases/tar/gnu-not-utf8.tar and /dev/null differ | |||
test/cases/tar/gnu-utf8.tar deleted| Binary files a/test/cases/tar/gnu-utf8.tar and /dev/null differ | |||
test/cases/tar/gnu.tar deleted| Binary files a/test/cases/tar/gnu.tar and /dev/null differ | |||
test/cases/tar/invalid-go17.tar deleted| Binary files a/test/cases/tar/invalid-go17.tar and /dev/null differ | |||
test/cases/tar/issue10968.tar deleted| Binary files a/test/cases/tar/issue10968.tar and /dev/null differ | |||
test/cases/tar/issue11169.tar deleted| Binary files a/test/cases/tar/issue11169.tar and /dev/null differ | |||
test/cases/tar/issue12435.tar deleted| Binary files a/test/cases/tar/issue12435.tar and /dev/null differ | |||
test/cases/tar/neg-size.tar deleted| Binary files a/test/cases/tar/neg-size.tar and /dev/null differ | |||
test/cases/tar/nil-uid.tar deleted| Binary files a/test/cases/tar/nil-uid.tar and /dev/null differ | |||
test/cases/tar/pax-bad-hdr-file.tar deleted| Binary files a/test/cases/tar/pax-bad-hdr-file.tar and /dev/null differ | |||
test/cases/tar/pax-global-records.tar deleted| Binary files a/test/cases/tar/pax-global-records.tar and /dev/null differ | |||
test/cases/tar/pax-multi-hdrs.tar deleted| Binary files a/test/cases/tar/pax-multi-hdrs.tar and /dev/null differ | |||
test/cases/tar/pax-nul-path.tar deleted| Binary files a/test/cases/tar/pax-nul-path.tar and /dev/null differ | |||
test/cases/tar/pax-nul-xattrs.tar deleted| Binary files a/test/cases/tar/pax-nul-xattrs.tar and /dev/null differ | |||
test/cases/tar/pax-pos-size-file.tar deleted| Binary files a/test/cases/tar/pax-pos-size-file.tar and /dev/null differ | |||
test/cases/tar/pax-records.tar deleted| Binary files a/test/cases/tar/pax-records.tar and /dev/null differ | |||
test/cases/tar/pax.tar deleted| Binary files a/test/cases/tar/pax.tar and /dev/null differ | |||
test/cases/tar/sparse-formats.tar deleted| Binary files a/test/cases/tar/sparse-formats.tar and /dev/null differ | |||
test/cases/tar/star.tar deleted| Binary files a/test/cases/tar/star.tar and /dev/null differ | |||
test/cases/tar/trailing-slash.tar deleted| Binary files a/test/cases/tar/trailing-slash.tar and /dev/null differ | |||
test/cases/tar/ustar-file-devs.tar deleted| Binary files a/test/cases/tar/ustar-file-devs.tar and /dev/null differ | |||
test/cases/tar/v7.tar deleted| Binary files a/test/cases/tar/v7.tar and /dev/null differ | |||
test/cases/tar/writer-big-long.tar deleted| Binary files a/test/cases/tar/writer-big-long.tar and /dev/null differ | |||
test/cases/tar/writer-big.tar deleted| Binary files a/test/cases/tar/writer-big.tar and /dev/null differ | |||
test/cases/tar/xattrs.tar deleted| Binary files a/test/cases/tar/xattrs.tar and /dev/null differ | |||