Fixed a handful of errors when extracting.
Fixed issues with unsquashfs
This commit is contained in:
+3
-7
@@ -30,17 +30,13 @@ pub fn readDir(alloc: std.mem.Allocator, rdr: *Reader, size: u32) ![]Entry {
|
||||
var cur_red: u32 = 3; // start at 3 due to "." & ".." being counted in the dir size.
|
||||
var hdr: Header = undefined;
|
||||
var raw: RawEntry = undefined;
|
||||
var out: std.ArrayList(Entry) = try .initCapacity(alloc, 25); // Start out with capacity instead of needing to allocate per header.
|
||||
var out: std.ArrayList(Entry) = try .initCapacity(alloc, 100); // Start out with a decent capacity instead of needing to allocate per header.
|
||||
errdefer out.deinit(alloc);
|
||||
while (cur_red < size) {
|
||||
try rdr.readSliceEndian(Header, @ptrCast(&hdr), .little);
|
||||
cur_red += @sizeOf(Header);
|
||||
const count = hdr.count + 1;
|
||||
if (out.capacity < count) {
|
||||
// Make sure we have at least 25 capacity past current count.
|
||||
try out.ensureUnusedCapacity(alloc, ((count % 25) + 2) * 25);
|
||||
}
|
||||
for (0..count) |_| {
|
||||
try out.ensureUnusedCapacity(alloc, hdr.count + 1);
|
||||
for (0..hdr.count + 1) |_| {
|
||||
try rdr.readSliceEndian(RawEntry, @ptrCast(&raw), .little);
|
||||
const name = try alloc.alloc(u8, raw.name_size + 1);
|
||||
errdefer alloc.free(name);
|
||||
|
||||
Reference in New Issue
Block a user