-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Closed
Labels
contributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.This issue is limited in scope and/or knowledge of Zig internals.enhancementSolving this issue will likely involve adding new logic or components to the codebase.Solving this issue will likely involve adding new logic or components to the codebase.zig build systemstd.Build, the build runner, `zig build` subcommand, package managementstd.Build, the build runner, `zig build` subcommand, package management
Milestone
Description
zig fetch foo.zip should work.
Relevant logic is here:
Lines 946 to 1024 in f7bc55c
| fn unpackResource( | |
| f: *Fetch, | |
| resource: *Resource, | |
| uri_path: []const u8, | |
| tmp_directory: Cache.Directory, | |
| ) RunError!void { | |
| const eb = &f.error_bundle; | |
| const file_type = switch (resource.*) { | |
| .file => FileType.fromPath(uri_path) orelse | |
| return f.fail(f.location_tok, try eb.printString("unknown file type: '{s}'", .{uri_path})), | |
| .http_request => |req| ft: { | |
| // Content-Type takes first precedence. | |
| const content_type = req.response.headers.getFirstValue("Content-Type") orelse | |
| return f.fail(f.location_tok, try eb.addString("missing 'Content-Type' header")); | |
| if (ascii.eqlIgnoreCase(content_type, "application/x-tar")) | |
| break :ft .tar; | |
| if (ascii.eqlIgnoreCase(content_type, "application/gzip") or | |
| ascii.eqlIgnoreCase(content_type, "application/x-gzip") or | |
| ascii.eqlIgnoreCase(content_type, "application/tar+gzip")) | |
| { | |
| break :ft .@"tar.gz"; | |
| } | |
| if (ascii.eqlIgnoreCase(content_type, "application/x-xz")) | |
| break :ft .@"tar.xz"; | |
| if (!ascii.eqlIgnoreCase(content_type, "application/octet-stream")) { | |
| return f.fail(f.location_tok, try eb.printString( | |
| "unrecognized 'Content-Type' header: '{s}'", | |
| .{content_type}, | |
| )); | |
| } | |
| // Next, the filename from 'content-disposition: attachment' takes precedence. | |
| if (req.response.headers.getFirstValue("Content-Disposition")) |cd_header| { | |
| break :ft FileType.fromContentDisposition(cd_header) orelse { | |
| return f.fail(f.location_tok, try eb.printString( | |
| "unsupported Content-Disposition header value: '{s}' for Content-Type=application/octet-stream", | |
| .{cd_header}, | |
| )); | |
| }; | |
| } | |
| // Finally, the path from the URI is used. | |
| break :ft FileType.fromPath(uri_path) orelse { | |
| return f.fail(f.location_tok, try eb.printString( | |
| "unknown file type: '{s}'", | |
| .{uri_path}, | |
| )); | |
| }; | |
| }, | |
| .git => .git_pack, | |
| .dir => |dir| return f.recursiveDirectoryCopy(dir, tmp_directory.handle) catch |err| { | |
| return f.fail(f.location_tok, try eb.printString( | |
| "unable to copy directory '{s}': {s}", | |
| .{ uri_path, @errorName(err) }, | |
| )); | |
| }, | |
| }; | |
| switch (file_type) { | |
| .tar => try unpackTarball(f, tmp_directory.handle, resource.reader()), | |
| .@"tar.gz" => try unpackTarballCompressed(f, tmp_directory.handle, resource, std.compress.gzip), | |
| .@"tar.xz" => try unpackTarballCompressed(f, tmp_directory.handle, resource, std.compress.xz), | |
| .git_pack => unpackGitPack(f, tmp_directory.handle, resource) catch |err| switch (err) { | |
| error.FetchFailed => return error.FetchFailed, | |
| error.OutOfMemory => return error.OutOfMemory, | |
| else => |e| return f.fail(f.location_tok, try eb.printString( | |
| "unable to unpack git files: {s}", | |
| .{@errorName(e)}, | |
| )), | |
| }, | |
| } | |
| } |
jethrodaniel and recursiveGeckoMFAshby, Game4all and ThePotatoChronicler
Metadata
Metadata
Assignees
Labels
contributor friendlyThis issue is limited in scope and/or knowledge of Zig internals.This issue is limited in scope and/or knowledge of Zig internals.enhancementSolving this issue will likely involve adding new logic or components to the codebase.Solving this issue will likely involve adding new logic or components to the codebase.zig build systemstd.Build, the build runner, `zig build` subcommand, package managementstd.Build, the build runner, `zig build` subcommand, package management