Archive.extract now directly uses Inode instead of File.
This commit is contained in:
@@ -1,14 +1,16 @@
|
||||
const std = @import("std");
|
||||
|
||||
pub fn build(b: *std.Build) void {
|
||||
const static = b.option(bool, "static_build", "Build static");
|
||||
const target = b.standardTargetOptions(.{});
|
||||
const optimize = b.standardOptimizeOption(.{ .preferred_optimize_mode = .ReleaseFast });
|
||||
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", .{
|
||||
.root_source_file = b.path("src/root.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
// .imports = &.{},
|
||||
});
|
||||
const exe = b.addExecutable(.{
|
||||
.name = "unsquashfs",
|
||||
|
||||
+20
-3
@@ -141,7 +141,24 @@ pub fn open(self: *Archive, path: []const u8) !SfsFile {
|
||||
|
||||
pub fn extract(self: *Archive, path: []const u8, options: ExtractionOptions) !void {
|
||||
if (!self.setup) try self.setupValues();
|
||||
var root_fil = try self.root();
|
||||
defer root_fil.deinit();
|
||||
return root_fil.extract(path, options);
|
||||
var alloc = self.allocator();
|
||||
var ext_path: []u8 = undefined;
|
||||
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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user