| ... | ... | @@ -15,10 +15,10 @@ const Compilation = @import("Compilation.zig"); |
| 15 | 15 | const Module = @import("Module.zig"); |
| 16 | 16 | const Cache = std.Build.Cache; |
| 17 | 17 | const build_options = @import("build_options"); |
| 18 | | const Manifest = @import("Manifest.zig"); |
| 19 | 18 | const git = @import("git.zig"); |
| 20 | 19 | const computePackageHash = @import("Package/hash.zig").compute; |
| 21 | 20 | |
| 21 | pub const Manifest = @import("Manifest.zig"); |
| 22 | 22 | pub const Table = std.StringHashMapUnmanaged(*Package); |
| 23 | 23 | |
| 24 | 24 | root_src_directory: Compilation.Directory, |
| ... | ... | @@ -454,8 +454,8 @@ pub fn createFilePkg( |
| 454 | 454 | return createWithDir(gpa, cache_directory, o_dir_sub_path, basename); |
| 455 | 455 | } |
| 456 | 456 | |
| 457 | | const Report = struct { |
| 458 | | ast: *const std.zig.Ast, |
| 457 | pub const Report = struct { |
| 458 | ast: ?*const std.zig.Ast, |
| 459 | 459 | directory: Compilation.Directory, |
| 460 | 460 | error_bundle: *std.zig.ErrorBundle.Wip, |
| 461 | 461 | |
| ... | ... | @@ -465,6 +465,7 @@ const Report = struct { |
| 465 | 465 | comptime fmt_string: []const u8, |
| 466 | 466 | fmt_args: anytype, |
| 467 | 467 | ) error{ PackageFetchFailed, OutOfMemory } { |
| 468 | const ast = report.ast orelse main.fatal(fmt_string, fmt_args); |
| 468 | 469 | const gpa = report.error_bundle.gpa; |
| 469 | 470 | |
| 470 | 471 | const file_path = try report.directory.join(gpa, &.{Manifest.basename}); |
| ... | ... | @@ -473,7 +474,7 @@ const Report = struct { |
| 473 | 474 | const msg = try std.fmt.allocPrint(gpa, fmt_string, fmt_args); |
| 474 | 475 | defer gpa.free(msg); |
| 475 | 476 | |
| 476 | | try addErrorMessage(report.ast.*, file_path, report.error_bundle, 0, .{ |
| 477 | try addErrorMessage(ast.*, file_path, report.error_bundle, 0, .{ |
| 477 | 478 | .tok = tok, |
| 478 | 479 | .off = 0, |
| 479 | 480 | .msg = msg, |
| ... | ... | @@ -482,6 +483,18 @@ const Report = struct { |
| 482 | 483 | return error.PackageFetchFailed; |
| 483 | 484 | } |
| 484 | 485 | |
| 486 | fn addErrorWithNotes( |
| 487 | report: Report, |
| 488 | notes_len: u32, |
| 489 | msg: Manifest.ErrorMessage, |
| 490 | ) error{OutOfMemory}!void { |
| 491 | const ast = report.ast orelse main.fatal("{s}", .{msg.msg}); |
| 492 | const gpa = report.error_bundle.gpa; |
| 493 | const file_path = try report.directory.join(gpa, &.{Manifest.basename}); |
| 494 | defer gpa.free(file_path); |
| 495 | return addErrorMessage(ast.*, file_path, report.error_bundle, notes_len, msg); |
| 496 | } |
| 497 | |
| 485 | 498 | fn addErrorMessage( |
| 486 | 499 | ast: std.zig.Ast, |
| 487 | 500 | file_path: []const u8, |
| ... | ... | @@ -508,7 +521,7 @@ const Report = struct { |
| 508 | 521 | } |
| 509 | 522 | }; |
| 510 | 523 | |
| 511 | | const FetchLocation = union(enum) { |
| 524 | pub const FetchLocation = union(enum) { |
| 512 | 525 | /// The relative path to a file or directory. |
| 513 | 526 | /// This may be a file that requires unpacking (such as a .tar.gz), |
| 514 | 527 | /// or the path to the root directory of a package. |
| ... | ... | @@ -517,30 +530,27 @@ const FetchLocation = union(enum) { |
| 517 | 530 | http_request: std.Uri, |
| 518 | 531 | git_request: std.Uri, |
| 519 | 532 | |
| 520 | | pub fn init(gpa: Allocator, dep: Manifest.Dependency, root_dir: Compilation.Directory, report: Report) !FetchLocation { |
| 533 | pub fn init( |
| 534 | gpa: Allocator, |
| 535 | dep: Manifest.Dependency, |
| 536 | root_dir: Compilation.Directory, |
| 537 | report: Report, |
| 538 | ) !FetchLocation { |
| 521 | 539 | switch (dep.location) { |
| 522 | 540 | .url => |url| { |
| 523 | 541 | const uri = std.Uri.parse(url) catch |err| switch (err) { |
| 524 | 542 | error.UnexpectedCharacter => return report.fail(dep.location_tok, "failed to parse dependency location as URI", .{}), |
| 525 | 543 | else => return err, |
| 526 | 544 | }; |
| 527 | | if (ascii.eqlIgnoreCase(uri.scheme, "file")) { |
| 528 | | return report.fail(dep.location_tok, "'file' scheme is not allowed for URLs. Use '.path' instead", .{}); |
| 529 | | } else if (ascii.eqlIgnoreCase(uri.scheme, "http") or ascii.eqlIgnoreCase(uri.scheme, "https")) { |
| 530 | | return .{ .http_request = uri }; |
| 531 | | } else if (ascii.eqlIgnoreCase(uri.scheme, "git+http") or ascii.eqlIgnoreCase(uri.scheme, "git+https")) { |
| 532 | | return .{ .git_request = uri }; |
| 533 | | } else { |
| 534 | | return report.fail(dep.location_tok, "Unsupported URL scheme: {s}", .{uri.scheme}); |
| 535 | | } |
| 545 | return initUri(uri, dep.location_tok, report); |
| 536 | 546 | }, |
| 537 | 547 | .path => |path| { |
| 538 | 548 | if (fs.path.isAbsolute(path)) { |
| 539 | | return report.fail(dep.location_tok, "Absolute paths are not allowed. Use a relative path instead", .{}); |
| 549 | return report.fail(dep.location_tok, "absolute paths are not allowed. Use a relative path instead", .{}); |
| 540 | 550 | } |
| 541 | 551 | |
| 542 | 552 | const is_dir = isDirectory(root_dir, path) catch |err| switch (err) { |
| 543 | | error.FileNotFound => return report.fail(dep.location_tok, "File not found: {s}", .{path}), |
| 553 | error.FileNotFound => return report.fail(dep.location_tok, "file not found: {s}", .{path}), |
| 544 | 554 | else => return err, |
| 545 | 555 | }; |
| 546 | 556 | |
| ... | ... | @@ -552,9 +562,21 @@ const FetchLocation = union(enum) { |
| 552 | 562 | } |
| 553 | 563 | } |
| 554 | 564 | |
| 565 | pub fn initUri(uri: std.Uri, location_tok: std.zig.Ast.TokenIndex, report: Report) !FetchLocation { |
| 566 | if (ascii.eqlIgnoreCase(uri.scheme, "file")) { |
| 567 | return report.fail(location_tok, "'file' scheme is not allowed for URLs. Use '.path' instead", .{}); |
| 568 | } else if (ascii.eqlIgnoreCase(uri.scheme, "http") or ascii.eqlIgnoreCase(uri.scheme, "https")) { |
| 569 | return .{ .http_request = uri }; |
| 570 | } else if (ascii.eqlIgnoreCase(uri.scheme, "git+http") or ascii.eqlIgnoreCase(uri.scheme, "git+https")) { |
| 571 | return .{ .git_request = uri }; |
| 572 | } else { |
| 573 | return report.fail(location_tok, "unsupported URL scheme: {s}", .{uri.scheme}); |
| 574 | } |
| 575 | } |
| 576 | |
| 555 | 577 | pub fn deinit(f: *FetchLocation, gpa: Allocator) void { |
| 556 | 578 | switch (f.*) { |
| 557 | | inline .file, .directory => |path| gpa.free(path), |
| 579 | .file, .directory => |path| gpa.free(path), |
| 558 | 580 | .http_request, .git_request => {}, |
| 559 | 581 | } |
| 560 | 582 | f.* = undefined; |
| ... | ... | @@ -565,7 +587,7 @@ const FetchLocation = union(enum) { |
| 565 | 587 | gpa: Allocator, |
| 566 | 588 | root_dir: Compilation.Directory, |
| 567 | 589 | http_client: *std.http.Client, |
| 568 | | dep: Manifest.Dependency, |
| 590 | dep_location_tok: std.zig.Ast.TokenIndex, |
| 569 | 591 | report: Report, |
| 570 | 592 | ) !ReadableResource { |
| 571 | 593 | switch (f) { |
| ... | ... | @@ -588,7 +610,7 @@ const FetchLocation = union(enum) { |
| 588 | 610 | try req.wait(); |
| 589 | 611 | |
| 590 | 612 | if (req.response.status != .ok) { |
| 591 | | return report.fail(dep.location_tok, "Expected response status '200 OK' got '{} {s}'", .{ |
| 613 | return report.fail(dep_location_tok, "expected response status '200 OK' got '{} {s}'", .{ |
| 592 | 614 | @intFromEnum(req.response.status), |
| 593 | 615 | req.response.status.phrase() orelse "", |
| 594 | 616 | }); |
| ... | ... | @@ -607,7 +629,7 @@ const FetchLocation = union(enum) { |
| 607 | 629 | session.discoverCapabilities(gpa, &redirect_uri) catch |e| switch (e) { |
| 608 | 630 | error.Redirected => { |
| 609 | 631 | defer gpa.free(redirect_uri); |
| 610 | | return report.fail(dep.location_tok, "Repository moved to {s}", .{redirect_uri}); |
| 632 | return report.fail(dep_location_tok, "repository moved to {s}", .{redirect_uri}); |
| 611 | 633 | }, |
| 612 | 634 | else => |other| return other, |
| 613 | 635 | }; |
| ... | ... | @@ -634,19 +656,16 @@ const FetchLocation = union(enum) { |
| 634 | 656 | break :want_oid ref.peeled orelse ref.oid; |
| 635 | 657 | } |
| 636 | 658 | } |
| 637 | | return report.fail(dep.location_tok, "Ref not found: {s}", .{want_ref}); |
| 659 | return report.fail(dep_location_tok, "ref not found: {s}", .{want_ref}); |
| 638 | 660 | }; |
| 639 | 661 | if (uri.fragment == null) { |
| 640 | | const file_path = try report.directory.join(gpa, &.{Manifest.basename}); |
| 641 | | defer gpa.free(file_path); |
| 642 | | |
| 643 | | const eb = report.error_bundle; |
| 644 | 662 | const notes_len = 1; |
| 645 | | try Report.addErrorMessage(report.ast.*, file_path, eb, notes_len, .{ |
| 646 | | .tok = dep.location_tok, |
| 663 | try report.addErrorWithNotes(notes_len, .{ |
| 664 | .tok = dep_location_tok, |
| 647 | 665 | .off = 0, |
| 648 | 666 | .msg = "url field is missing an explicit ref", |
| 649 | 667 | }); |
| 668 | const eb = report.error_bundle; |
| 650 | 669 | const notes_start = try eb.reserveNotes(notes_len); |
| 651 | 670 | eb.extra.items[notes_start] = @intFromEnum(try eb.addErrorMessage(.{ |
| 652 | 671 | .msg = try eb.printString("try .url = \"{+/}#{}\",", .{ uri, std.fmt.fmtSliceHexLower(&want_oid) }), |
| ... | ... | @@ -669,12 +688,13 @@ const FetchLocation = union(enum) { |
| 669 | 688 | } |
| 670 | 689 | }; |
| 671 | 690 | |
| 672 | | const ReadableResource = struct { |
| 691 | pub const ReadableResource = struct { |
| 673 | 692 | path: []const u8, |
| 674 | 693 | resource: union(enum) { |
| 675 | 694 | file: fs.File, |
| 676 | 695 | http_request: std.http.Client.Request, |
| 677 | 696 | git_fetch_stream: git.Session.FetchStream, |
| 697 | dir: fs.IterableDir, |
| 678 | 698 | }, |
| 679 | 699 | |
| 680 | 700 | /// Unpack the package into the global cache directory. |
| ... | ... | @@ -685,12 +705,12 @@ const ReadableResource = struct { |
| 685 | 705 | allocator: Allocator, |
| 686 | 706 | thread_pool: *ThreadPool, |
| 687 | 707 | global_cache_directory: Compilation.Directory, |
| 688 | | dep: Manifest.Dependency, |
| 708 | dep_location_tok: std.zig.Ast.TokenIndex, |
| 689 | 709 | report: Report, |
| 690 | 710 | pkg_prog_node: *std.Progress.Node, |
| 691 | 711 | ) !PackageLocation { |
| 692 | 712 | switch (rr.resource) { |
| 693 | | inline .file, .http_request, .git_fetch_stream => |*r| { |
| 713 | inline .file, .http_request, .git_fetch_stream, .dir => |*r, tag| { |
| 694 | 714 | const s = fs.path.sep_str; |
| 695 | 715 | const rand_int = std.crypto.random.int(u64); |
| 696 | 716 | const tmp_dir_sub_path = "tmp" ++ s ++ Manifest.hex64(rand_int); |
| ... | ... | @@ -710,45 +730,58 @@ const ReadableResource = struct { |
| 710 | 730 | }; |
| 711 | 731 | defer tmp_directory.closeAndFree(allocator); |
| 712 | 732 | |
| 713 | | const opt_content_length = try rr.getSize(); |
| 714 | | |
| 715 | | var prog_reader: ProgressReader(@TypeOf(r.reader())) = .{ |
| 716 | | .child_reader = r.reader(), |
| 717 | | .prog_node = pkg_prog_node, |
| 718 | | .unit = if (opt_content_length) |content_length| unit: { |
| 719 | | const kib = content_length / 1024; |
| 720 | | const mib = kib / 1024; |
| 721 | | if (mib > 0) { |
| 722 | | pkg_prog_node.setEstimatedTotalItems(@intCast(mib)); |
| 723 | | pkg_prog_node.setUnit("MiB"); |
| 724 | | break :unit .mib; |
| 725 | | } else { |
| 726 | | pkg_prog_node.setEstimatedTotalItems(@intCast(@max(1, kib))); |
| 727 | | pkg_prog_node.setUnit("KiB"); |
| 728 | | break :unit .kib; |
| 733 | if (tag != .dir) { |
| 734 | const opt_content_length = try rr.getSize(); |
| 735 | |
| 736 | var prog_reader: ProgressReader(@TypeOf(r.reader())) = .{ |
| 737 | .child_reader = r.reader(), |
| 738 | .prog_node = pkg_prog_node, |
| 739 | .unit = if (opt_content_length) |content_length| unit: { |
| 740 | const kib = content_length / 1024; |
| 741 | const mib = kib / 1024; |
| 742 | if (mib > 0) { |
| 743 | pkg_prog_node.setEstimatedTotalItems(@intCast(mib)); |
| 744 | pkg_prog_node.setUnit("MiB"); |
| 745 | break :unit .mib; |
| 746 | } else { |
| 747 | pkg_prog_node.setEstimatedTotalItems(@intCast(@max(1, kib))); |
| 748 | pkg_prog_node.setUnit("KiB"); |
| 749 | break :unit .kib; |
| 750 | } |
| 751 | } else .any, |
| 752 | }; |
| 753 | |
| 754 | switch (try rr.getFileType(dep_location_tok, report)) { |
| 755 | .tar => try unpackTarball(prog_reader.reader(), tmp_directory.handle), |
| 756 | .@"tar.gz" => try unpackTarballCompressed(allocator, prog_reader, tmp_directory.handle, std.compress.gzip), |
| 757 | .@"tar.xz" => try unpackTarballCompressed(allocator, prog_reader, tmp_directory.handle, std.compress.xz), |
| 758 | .git_pack => try unpackGitPack(allocator, &prog_reader, git.parseOid(rr.path) catch unreachable, tmp_directory.handle), |
| 759 | } |
| 760 | } else { |
| 761 | // Recursive directory copy. |
| 762 | var it = try r.walk(allocator); |
| 763 | defer it.deinit(); |
| 764 | while (try it.next()) |entry| { |
| 765 | switch (entry.kind) { |
| 766 | .directory => try tmp_directory.handle.makePath(entry.path), |
| 767 | .file => try r.dir.copyFile( |
| 768 | entry.path, |
| 769 | tmp_directory.handle, |
| 770 | entry.path, |
| 771 | .{}, |
| 772 | ), |
| 773 | .sym_link => { |
| 774 | var buf: [fs.MAX_PATH_BYTES]u8 = undefined; |
| 775 | const link_name = try r.dir.readLink(entry.path, &buf); |
| 776 | // TODO: if this would create a symlink to outside |
| 777 | // the destination directory, fail with an error instead. |
| 778 | try tmp_directory.handle.symLink(link_name, entry.path, .{}); |
| 779 | }, |
| 780 | else => return error.IllegalFileTypeInPackage, |
| 729 | 781 | } |
| 730 | | } else .any, |
| 731 | | }; |
| 732 | | pkg_prog_node.context.refresh(); |
| 733 | | |
| 734 | | switch (try rr.getFileType(dep, report)) { |
| 735 | | .@"tar.gz" => try unpackTarball(allocator, prog_reader, tmp_directory.handle, std.compress.gzip), |
| 736 | | // I have not checked what buffer sizes the xz decompression implementation uses |
| 737 | | // by default, so the same logic applies for buffering the reader as for gzip. |
| 738 | | .@"tar.xz" => try unpackTarball(allocator, prog_reader, tmp_directory.handle, std.compress.xz), |
| 739 | | .git_pack => try unpackGitPack(allocator, &prog_reader, git.parseOid(rr.path) catch unreachable, tmp_directory.handle), |
| 782 | } |
| 740 | 783 | } |
| 741 | 784 | |
| 742 | | // Unpack completed - stop showing amount as progress |
| 743 | | pkg_prog_node.setEstimatedTotalItems(0); |
| 744 | | pkg_prog_node.setCompletedItems(0); |
| 745 | | pkg_prog_node.context.refresh(); |
| 746 | | |
| 747 | | // TODO: delete files not included in the package prior to computing the package hash. |
| 748 | | // for example, if the ini file has directives to include/not include certain files, |
| 749 | | // apply those rules directly to the filesystem right here. This ensures that files |
| 750 | | // not protected by the hash are not present on the file system. |
| 751 | | |
| 752 | 785 | break :h try computePackageHash(thread_pool, .{ .dir = tmp_directory.handle }); |
| 753 | 786 | }; |
| 754 | 787 | |
| ... | ... | @@ -769,6 +802,7 @@ const ReadableResource = struct { |
| 769 | 802 | } |
| 770 | 803 | |
| 771 | 804 | const FileType = enum { |
| 805 | tar, |
| 772 | 806 | @"tar.gz", |
| 773 | 807 | @"tar.xz", |
| 774 | 808 | git_pack, |
| ... | ... | @@ -780,21 +814,28 @@ const ReadableResource = struct { |
| 780 | 814 | // TODO: Handle case of chunked content-length |
| 781 | 815 | .http_request => |req| return req.response.content_length, |
| 782 | 816 | .git_fetch_stream => |stream| return stream.request.response.content_length, |
| 817 | .dir => unreachable, |
| 783 | 818 | } |
| 784 | 819 | } |
| 785 | 820 | |
| 786 | | pub fn getFileType(rr: ReadableResource, dep: Manifest.Dependency, report: Report) !FileType { |
| 821 | pub fn getFileType( |
| 822 | rr: ReadableResource, |
| 823 | dep_location_tok: std.zig.Ast.TokenIndex, |
| 824 | report: Report, |
| 825 | ) !FileType { |
| 787 | 826 | switch (rr.resource) { |
| 788 | 827 | .file => { |
| 789 | 828 | return fileTypeFromPath(rr.path) orelse |
| 790 | | return report.fail(dep.location_tok, "Unknown file type", .{}); |
| 829 | return report.fail(dep_location_tok, "unknown file type", .{}); |
| 791 | 830 | }, |
| 792 | 831 | .http_request => |req| { |
| 793 | 832 | const content_type = req.response.headers.getFirstValue("Content-Type") orelse |
| 794 | | return report.fail(dep.location_tok, "Missing 'Content-Type' header", .{}); |
| 833 | return report.fail(dep_location_tok, "missing 'Content-Type' header", .{}); |
| 795 | 834 | |
| 796 | 835 | // If the response has a different content type than the URI indicates, override |
| 797 | 836 | // the previously assumed file type. |
| 837 | if (ascii.eqlIgnoreCase(content_type, "application/x-tar")) return .tar; |
| 838 | |
| 798 | 839 | return if (ascii.eqlIgnoreCase(content_type, "application/gzip") or |
| 799 | 840 | ascii.eqlIgnoreCase(content_type, "application/x-gzip") or |
| 800 | 841 | ascii.eqlIgnoreCase(content_type, "application/tar+gzip")) |
| ... | ... | @@ -805,22 +846,21 @@ const ReadableResource = struct { |
| 805 | 846 | // support gitlab tarball urls such as https://gitlab.com/<namespace>/<project>/-/archive/<sha>/<project>-<sha>.tar.gz |
| 806 | 847 | // whose content-disposition header is: 'attachment; filename="<project>-<sha>.tar.gz"' |
| 807 | 848 | const content_disposition = req.response.headers.getFirstValue("Content-Disposition") orelse |
| 808 | | return report.fail(dep.location_tok, "Missing 'Content-Disposition' header for Content-Type=application/octet-stream", .{}); |
| 849 | return report.fail(dep_location_tok, "missing 'Content-Disposition' header for Content-Type=application/octet-stream", .{}); |
| 809 | 850 | break :ty getAttachmentType(content_disposition) orelse |
| 810 | | return report.fail(dep.location_tok, "Unsupported 'Content-Disposition' header value: '{s}' for Content-Type=application/octet-stream", .{content_disposition}); |
| 811 | | } else return report.fail(dep.location_tok, "Unrecognized value for 'Content-Type' header: {s}", .{content_type}); |
| 851 | return report.fail(dep_location_tok, "unsupported 'Content-Disposition' header value: '{s}' for Content-Type=application/octet-stream", .{content_disposition}); |
| 852 | } else return report.fail(dep_location_tok, "unrecognized value for 'Content-Type' header: {s}", .{content_type}); |
| 812 | 853 | }, |
| 813 | 854 | .git_fetch_stream => return .git_pack, |
| 855 | .dir => unreachable, |
| 814 | 856 | } |
| 815 | 857 | } |
| 816 | 858 | |
| 817 | 859 | fn fileTypeFromPath(file_path: []const u8) ?FileType { |
| 818 | | return if (ascii.endsWithIgnoreCase(file_path, ".tar.gz")) |
| 819 | | .@"tar.gz" |
| 820 | | else if (ascii.endsWithIgnoreCase(file_path, ".tar.xz")) |
| 821 | | .@"tar.xz" |
| 822 | | else |
| 823 | | null; |
| 860 | if (ascii.endsWithIgnoreCase(file_path, ".tar")) return .tar; |
| 861 | if (ascii.endsWithIgnoreCase(file_path, ".tar.gz")) return .@"tar.gz"; |
| 862 | if (ascii.endsWithIgnoreCase(file_path, ".tar.xz")) return .@"tar.xz"; |
| 863 | return null; |
| 824 | 864 | } |
| 825 | 865 | |
| 826 | 866 | fn getAttachmentType(content_disposition: []const u8) ?FileType { |
| ... | ... | @@ -847,6 +887,7 @@ const ReadableResource = struct { |
| 847 | 887 | .file => |file| file.close(), |
| 848 | 888 | .http_request => |*req| req.deinit(), |
| 849 | 889 | .git_fetch_stream => |*stream| stream.deinit(), |
| 890 | .dir => |*dir| dir.close(), |
| 850 | 891 | } |
| 851 | 892 | rr.* = undefined; |
| 852 | 893 | } |
| ... | ... | @@ -908,7 +949,7 @@ fn ProgressReader(comptime ReaderType: type) type { |
| 908 | 949 | } |
| 909 | 950 | }, |
| 910 | 951 | } |
| 911 | | self.prog_node.context.maybeRefresh(); |
| 952 | self.prog_node.activate(); |
| 912 | 953 | return amt; |
| 913 | 954 | } |
| 914 | 955 | |
| ... | ... | @@ -993,7 +1034,7 @@ fn getDirectoryModule( |
| 993 | 1034 | if (all_modules.get(hex_digest)) |mod| return .{ mod.?, true }; |
| 994 | 1035 | |
| 995 | 1036 | var pkg_dir = directory.handle.openDir(fetch_location.directory, .{}) catch |err| switch (err) { |
| 996 | | error.FileNotFound => return report.fail(dep.location_tok, "File not found: {s}", .{fetch_location.directory}), |
| 1037 | error.FileNotFound => return report.fail(dep.location_tok, "file not found: {s}", .{fetch_location.directory}), |
| 997 | 1038 | else => |e| return e, |
| 998 | 1039 | }; |
| 999 | 1040 | defer pkg_dir.close(); |
| ... | ... | @@ -1032,12 +1073,18 @@ fn fetchAndUnpack( |
| 1032 | 1073 | var pkg_prog_node = root_prog_node.start(name_for_prog, 0); |
| 1033 | 1074 | defer pkg_prog_node.end(); |
| 1034 | 1075 | pkg_prog_node.activate(); |
| 1035 | | pkg_prog_node.context.refresh(); |
| 1036 | 1076 | |
| 1037 | | var readable_resource = try fetch_location.fetch(gpa, directory, http_client, dep, report); |
| 1077 | var readable_resource = try fetch_location.fetch(gpa, directory, http_client, dep.location_tok, report); |
| 1038 | 1078 | defer readable_resource.deinit(gpa); |
| 1039 | 1079 | |
| 1040 | | var package_location = try readable_resource.unpack(gpa, thread_pool, global_cache_directory, dep, report, &pkg_prog_node); |
| 1080 | var package_location = try readable_resource.unpack( |
| 1081 | gpa, |
| 1082 | thread_pool, |
| 1083 | global_cache_directory, |
| 1084 | dep.location_tok, |
| 1085 | report, |
| 1086 | &pkg_prog_node, |
| 1087 | ); |
| 1041 | 1088 | defer package_location.deinit(gpa); |
| 1042 | 1089 | |
| 1043 | 1090 | const actual_hex = Manifest.hexDigest(package_location.hash); |
| ... | ... | @@ -1048,16 +1095,13 @@ fn fetchAndUnpack( |
| 1048 | 1095 | }); |
| 1049 | 1096 | } |
| 1050 | 1097 | } else { |
| 1051 | | const file_path = try report.directory.join(gpa, &.{Manifest.basename}); |
| 1052 | | defer gpa.free(file_path); |
| 1053 | | |
| 1054 | | const eb = report.error_bundle; |
| 1055 | 1098 | const notes_len = 1; |
| 1056 | | try Report.addErrorMessage(report.ast.*, file_path, eb, notes_len, .{ |
| 1099 | try report.addErrorWithNotes(notes_len, .{ |
| 1057 | 1100 | .tok = dep.location_tok, |
| 1058 | 1101 | .off = 0, |
| 1059 | 1102 | .msg = "dependency is missing hash field", |
| 1060 | 1103 | }); |
| 1104 | const eb = report.error_bundle; |
| 1061 | 1105 | const notes_start = try eb.reserveNotes(notes_len); |
| 1062 | 1106 | eb.extra.items[notes_start] = @intFromEnum(try eb.addErrorMessage(.{ |
| 1063 | 1107 | .msg = try eb.printString("expected .hash = \"{s}\",", .{&actual_hex}), |
| ... | ... | @@ -1080,18 +1124,22 @@ fn fetchAndUnpack( |
| 1080 | 1124 | return module; |
| 1081 | 1125 | } |
| 1082 | 1126 | |
| 1083 | | fn unpackTarball( |
| 1127 | fn unpackTarballCompressed( |
| 1084 | 1128 | gpa: Allocator, |
| 1085 | 1129 | reader: anytype, |
| 1086 | 1130 | out_dir: fs.Dir, |
| 1087 | | comptime compression: type, |
| 1131 | comptime Compression: type, |
| 1088 | 1132 | ) !void { |
| 1089 | 1133 | var br = std.io.bufferedReaderSize(std.crypto.tls.max_ciphertext_record_len, reader); |
| 1090 | 1134 | |
| 1091 | | var decompress = try compression.decompress(gpa, br.reader()); |
| 1135 | var decompress = try Compression.decompress(gpa, br.reader()); |
| 1092 | 1136 | defer decompress.deinit(); |
| 1093 | 1137 | |
| 1094 | | try std.tar.pipeToFileSystem(out_dir, decompress.reader(), .{ |
| 1138 | return unpackTarball(decompress.reader(), out_dir); |
| 1139 | } |
| 1140 | |
| 1141 | fn unpackTarball(reader: anytype, out_dir: fs.Dir) !void { |
| 1142 | try std.tar.pipeToFileSystem(out_dir, reader, .{ |
| 1095 | 1143 | .strip_components = 1, |
| 1096 | 1144 | // TODO: we would like to set this to executable_bit_only, but two |
| 1097 | 1145 | // things need to happen before that: |
| ... | ... | @@ -1126,7 +1174,6 @@ fn unpackGitPack( |
| 1126 | 1174 | var index_prog_node = reader.prog_node.start("Index pack", 0); |
| 1127 | 1175 | defer index_prog_node.end(); |
| 1128 | 1176 | index_prog_node.activate(); |
| 1129 | | index_prog_node.context.refresh(); |
| 1130 | 1177 | var index_buffered_writer = std.io.bufferedWriter(index_file.writer()); |
| 1131 | 1178 | try git.indexPack(gpa, pack_file, index_buffered_writer.writer()); |
| 1132 | 1179 | try index_buffered_writer.flush(); |
| ... | ... | @@ -1137,7 +1184,6 @@ fn unpackGitPack( |
| 1137 | 1184 | var checkout_prog_node = reader.prog_node.start("Checkout", 0); |
| 1138 | 1185 | defer checkout_prog_node.end(); |
| 1139 | 1186 | checkout_prog_node.activate(); |
| 1140 | | checkout_prog_node.context.refresh(); |
| 1141 | 1187 | var repository = try git.Repository.init(gpa, pack_file, index_file); |
| 1142 | 1188 | defer repository.deinit(); |
| 1143 | 1189 | try repository.checkout(out_dir, want_oid); |