Archive.extract now directly uses Inode instead of File.

This commit is contained in:
Caleb J. Gardner
2026-02-07 06:57:55 -06:00
parent 704215e1a9
commit b64a3ec44a
2 changed files with 23 additions and 4 deletions
+3 -1
View File
@@ -1,14 +1,16 @@
const std = @import("std"); const std = @import("std");
pub fn build(b: *std.Build) void { pub fn build(b: *std.Build) void {
const static = b.option(bool, "static_build", "Build static");
const target = b.standardTargetOptions(.{}); const target = b.standardTargetOptions(.{});
const optimize = b.standardOptimizeOption(.{ .preferred_optimize_mode = .ReleaseFast }); const optimize = b.standardOptimizeOption(.{ .preferred_optimize_mode = .ReleaseFast });
const linkage: std.builtin.LinkMode = .static; // TODO: Add argument to set link mode. const linkage: std.builtin.LinkMode = .static; // TODO: Add argument to set link mode.
const use_c_libs: bool = false;
_ = use_c_libs;
const mod = b.addModule("zig_squashfs", .{ const mod = b.addModule("zig_squashfs", .{
.root_source_file = b.path("src/root.zig"), .root_source_file = b.path("src/root.zig"),
.target = target, .target = target,
.optimize = optimize, .optimize = optimize,
// .imports = &.{},
}); });
const exe = b.addExecutable(.{ const exe = b.addExecutable(.{
.name = "unsquashfs", .name = "unsquashfs",
+20 -3
View File
@@ -141,7 +141,24 @@ pub fn open(self: *Archive, path: []const u8) !SfsFile {
pub fn extract(self: *Archive, path: []const u8, options: ExtractionOptions) !void { pub fn extract(self: *Archive, path: []const u8, options: ExtractionOptions) !void {
if (!self.setup) try self.setupValues(); if (!self.setup) try self.setupValues();
var root_fil = try self.root(); var alloc = self.allocator();
defer root_fil.deinit(); var ext_path: []u8 = undefined;
return root_fil.extract(path, options); if (std.fs.cwd().statFile(path)) |stat| {
if (stat.kind == .directory) {
ext_path = @constCast(path);
} else return error.ExtractionPathExists;
} else |err| {
if (err == error.FileNotFound) {
ext_path = @constCast(path);
} else {
std.log.err("Error stat-ing extraction path {s}: {}\n", .{ path, err });
return err;
}
}
defer if (ext_path.len > path.len) alloc.free(ext_path);
var rdr = try self.fil.readerAt(self.super.root_ref.block_start + self.super.inode_start, &[0]u8{});
var meta: MetadataReader = .init(self.allocator(), &rdr.interface, self.decomp);
try meta.interface.discardAll(self.super.root_ref.block_offset);
const in: Inode = try .read(self.allocator(), &meta.interface, self.super.block_size);
try in.extractTo(self, ext_path, options);
} }