Compare commits
2 Commits
f47ef9ee46
...
aa6b61fc9f
| Author | SHA1 | Date | |
|---|---|---|---|
| aa6b61fc9f | |||
| 69a4599f78 |
Executable
+22
@@ -0,0 +1,22 @@
|
|||||||
|
#! /usr/bin/env bash
|
||||||
|
|
||||||
|
ARCHIVE="testing/LinuxPATest.sfs"
|
||||||
|
|
||||||
|
REF_EXT_LOC="testing/LinuxPAReference"
|
||||||
|
PROG_EXT_LOC="testing/LinuxPABinTest"
|
||||||
|
|
||||||
|
echo "Building with ReleaseFast"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
zig build -Doptimize=ReleaseFast
|
||||||
|
|
||||||
|
echo "Testing Multi-threaded Performance"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
hyperfine --warmup 5 --prepare "rm -rf $REF_EXT_LOC && rm -rf $PROG_EXT_LOC" "unsquashfs -d $REF_EXT_LOC $ARCHIVE" "zig-out/bin/unsquashfs -d $PROG_EXT_LOC $ARCHIVE"
|
||||||
|
|
||||||
|
echo ""
|
||||||
|
echo "Testing Single-threaded Performance"
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
hyperfine --warmup 5 --prepare "rm -rf $REF_EXT_LOC && rm -rf $PROG_EXT_LOC" "unsquashfs -p 1 -d $REF_EXT_LOC $ARCHIVE" "zig-out/bin/unsquashfs -p 1 -d $PROG_EXT_LOC $ARCHIVE"
|
||||||
@@ -90,24 +90,36 @@ pub fn build(b: *std.Build) !void {
|
|||||||
|
|
||||||
b.installArtifact(exe);
|
b.installArtifact(exe);
|
||||||
|
|
||||||
const mod_tests = b.addTest(.{
|
const lib_tests = b.addTest(.{
|
||||||
.root_module = lib.root_module,
|
.root_module = lib.root_module,
|
||||||
.use_llvm = debug,
|
.use_llvm = debug,
|
||||||
});
|
});
|
||||||
const run_mod_tests = b.addRunArtifact(mod_tests);
|
const run_lib_tests = b.addRunArtifact(lib_tests);
|
||||||
|
const exe_tests = b.addTest(.{
|
||||||
|
.root_module = exe.root_module,
|
||||||
|
.use_llvm = debug,
|
||||||
|
});
|
||||||
|
const run_exe_tests = b.addRunArtifact(exe_tests);
|
||||||
|
|
||||||
const test_step = b.step("test", "Run tests");
|
const test_step = b.step("test", "Run tests");
|
||||||
test_step.dependOn(&run_mod_tests.step);
|
test_step.dependOn(&run_lib_tests.step);
|
||||||
|
test_step.dependOn(&run_exe_tests.step);
|
||||||
|
|
||||||
// zls build check steps
|
// zls build check steps
|
||||||
const lib_check = b.addLibrary(.{
|
const lib_check = b.addLibrary(.{
|
||||||
.name = "squashfs",
|
.name = "squashfs",
|
||||||
.root_module = lib.root_module,
|
.root_module = lib.root_module,
|
||||||
|
.use_llvm = debug,
|
||||||
});
|
});
|
||||||
const exe_check = b.addExecutable(.{
|
const exe_check = b.addExecutable(.{
|
||||||
.name = "unsquashfs",
|
.name = "unsquashfs",
|
||||||
.root_module = exe.root_module,
|
.root_module = exe.root_module,
|
||||||
|
.use_llvm = debug,
|
||||||
});
|
});
|
||||||
const check = b.step("check", "Check if unsquashfs compiles");
|
const check = b.step("check", "Check if unsquashfs compiles");
|
||||||
check.dependOn(&lib_check.step);
|
check.dependOn(&lib_check.step);
|
||||||
check.dependOn(&exe_check.step);
|
check.dependOn(&exe_check.step);
|
||||||
|
|
||||||
|
test_step.dependOn(&lib_check.step);
|
||||||
|
test_step.dependOn(&exe_check.step);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +0,0 @@
|
|||||||
#!/bin/sh
|
|
||||||
|
|
||||||
zig test \
|
|
||||||
-lc \
|
|
||||||
-lz \
|
|
||||||
-llzma \
|
|
||||||
-lminilzo \
|
|
||||||
-llz4 \
|
|
||||||
-lzstd \
|
|
||||||
src/test.zig
|
|
||||||
@@ -2,8 +2,8 @@ const std = @import("std");
|
|||||||
const Io = std.Io;
|
const Io = std.Io;
|
||||||
const Writer = Io.Writer;
|
const Writer = Io.Writer;
|
||||||
const builtin = @import("builtin");
|
const builtin = @import("builtin");
|
||||||
const build = @import("build");
|
|
||||||
|
|
||||||
|
const build = @import("build");
|
||||||
const squashfs = @import("squashfs");
|
const squashfs = @import("squashfs");
|
||||||
|
|
||||||
//TODO: Add more options
|
//TODO: Add more options
|
||||||
@@ -52,14 +52,16 @@ pub fn main(init: std.process.Init) !void {
|
|||||||
var out = stdout.writer(io, &[0]u8{});
|
var out = stdout.writer(io, &[0]u8{});
|
||||||
defer out.interface.flush() catch {};
|
defer out.interface.flush() catch {};
|
||||||
|
|
||||||
try handleArgs(init.minimal.args, &out.interface);
|
try handleArgs(alloc, init.minimal.args, &out.interface);
|
||||||
if (archive.len == 0) {
|
if (archive.len == 0) {
|
||||||
try out.interface.print("You must provide a squashfs archive\n", .{});
|
try out.interface.print("You must provide a squashfs archive\n", .{});
|
||||||
try out.interface.print(help_mgs, .{});
|
try out.interface.print(help_mgs, .{});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var fil = try Io.Dir.cwd().openFile(io, archive, .{}); //TODO: Handle error gracefully.
|
var fil = try Io.Dir.cwd().openFile(io, archive, .{}); //TODO: Handle error gracefully.
|
||||||
defer fil.close(io);
|
defer fil.close(io);
|
||||||
|
|
||||||
var arc: squashfs.Archive = try .init(io, fil, offset); //TODO: Update when memory size matters. //TODO: Handle error gracefully.
|
var arc: squashfs.Archive = try .init(io, fil, offset); //TODO: Update when memory size matters. //TODO: Handle error gracefully.
|
||||||
defer arc.deinit(io);
|
defer arc.deinit(io);
|
||||||
const options: squashfs.ExtractionOptions = .{
|
const options: squashfs.ExtractionOptions = .{
|
||||||
@@ -89,7 +91,7 @@ pub fn main(init: std.process.Init) !void {
|
|||||||
defer sfs_fil.deinit();
|
defer sfs_fil.deinit();
|
||||||
|
|
||||||
const last_ind = std.mem.lastIndexOf(u8, files[i], "/");
|
const last_ind = std.mem.lastIndexOf(u8, files[i], "/");
|
||||||
const file_name = if (last_ind != null) files[i][last_ind..] else files[i];
|
const file_name = if (last_ind != null) files[i][last_ind.?..] else files[i];
|
||||||
|
|
||||||
const fil_ext_loc = if (ext_loc.len > 0)
|
const fil_ext_loc = if (ext_loc.len > 0)
|
||||||
try std.mem.concat(alloc, u8, &.{ ext_loc, "/", file_name })
|
try std.mem.concat(alloc, u8, &.{ ext_loc, "/", file_name })
|
||||||
@@ -128,7 +130,7 @@ fn handleArgs(alloc: std.mem.Allocator, main_args: std.process.Args, out: *Write
|
|||||||
return errors.InvalidArguments;
|
return errors.InvalidArguments;
|
||||||
}
|
}
|
||||||
if (!alloc.resize(files, files.len + 1)) {
|
if (!alloc.resize(files, files.len + 1)) {
|
||||||
const new_alloc = alloc.alloc([]const u8, files.len + 1);
|
const new_alloc = try alloc.alloc([:0]const u8, files.len + 1);
|
||||||
@memcpy(new_alloc[0..files.len], files);
|
@memcpy(new_alloc[0..files.len], files);
|
||||||
alloc.free(files);
|
alloc.free(files);
|
||||||
files = new_alloc;
|
files = new_alloc;
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ fn finishLoop(alloc: std.mem.Allocator, io: Io, sel: *Io.Select(ReturnUnion), id
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (dirs.popMax()) |path_ret| {
|
while (dirs.popMax()) |path_ret| {
|
||||||
if (path_ret.hdr.num != start_num)
|
defer if (path_ret.hdr.num != start_num)
|
||||||
alloc.free(path_ret.path);
|
alloc.free(path_ret.path);
|
||||||
|
|
||||||
var file = try Io.Dir.cwd().openFile(io, path_ret.path, .{});
|
var file = try Io.Dir.cwd().openFile(io, path_ret.path, .{});
|
||||||
|
|||||||
@@ -59,13 +59,6 @@ fn setMetadata(
|
|||||||
var fil: Io.File = try Io.Dir.cwd().openFile(io, path, .{});
|
var fil: Io.File = try Io.Dir.cwd().openFile(io, path, .{});
|
||||||
defer fil.close(io);
|
defer fil.close(io);
|
||||||
|
|
||||||
if (!options.ignore_permissions) {
|
|
||||||
try fil.setTimestamps(io, .{
|
|
||||||
.modify_timestamp = .init(Io.Timestamp.fromNanoseconds(@as(i96, @intCast(inode.hdr.mod_time)) * std.time.ns_per_s)),
|
|
||||||
});
|
|
||||||
try fil.setPermissions(io, @enumFromInt(inode.hdr.permissions));
|
|
||||||
try fil.setOwner(io, try id_table.get(io, inode.hdr.uid_idx), try id_table.get(io, inode.hdr.gid_idx));
|
|
||||||
}
|
|
||||||
if (!options.ignore_xattr and xattr_idx != null) {
|
if (!options.ignore_xattr and xattr_idx != null) {
|
||||||
const xattr = try xattr_table.get(alloc, io, xattr_idx.?);
|
const xattr = try xattr_table.get(alloc, io, xattr_idx.?);
|
||||||
defer xattr.deinit(alloc);
|
defer xattr.deinit(alloc);
|
||||||
@@ -76,6 +69,13 @@ fn setMetadata(
|
|||||||
return error.SetXattrError;
|
return error.SetXattrError;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (!options.ignore_permissions) {
|
||||||
|
try fil.setTimestamps(io, .{
|
||||||
|
.modify_timestamp = .init(Io.Timestamp.fromNanoseconds(@as(i96, @intCast(inode.hdr.mod_time)) * std.time.ns_per_s)),
|
||||||
|
});
|
||||||
|
try fil.setPermissions(io, @enumFromInt(inode.hdr.permissions));
|
||||||
|
try fil.setOwner(io, try id_table.get(io, inode.hdr.uid_idx), try id_table.get(io, inode.hdr.gid_idx));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn extractDir(
|
fn extractDir(
|
||||||
|
|||||||
Reference in New Issue
Block a user