fix unix2db
This commit is contained in:
parent
e79cdaffde
commit
c294d149fc
@ -72,7 +72,8 @@ pub fn fromReader(allocator: Allocator, reader: anytype) FromReaderError![]Group
|
||||
var line = ArrayList(u8).init(allocator);
|
||||
defer line.deinit();
|
||||
|
||||
while (true) {
|
||||
var i: usize = 0;
|
||||
while (true) : (i += 1) {
|
||||
// TODO: catch and interpret different errors
|
||||
const max = std.math.maxInt(u32);
|
||||
reader.readUntilDelimiterArrayList(&line, '\n', max) catch |err| switch (err) {
|
||||
@ -94,7 +95,8 @@ pub fn fromReader(allocator: Allocator, reader: anytype) FromReaderError![]Group
|
||||
while (members_it.next()) |member|
|
||||
try member_ptrs.append(member);
|
||||
|
||||
try groups.append(try init(allocator, gid, name, member_ptrs.items));
|
||||
const group = try init(allocator, gid, name, member_ptrs.items);
|
||||
try groups.append(group);
|
||||
member_ptrs.shrinkRetainingCapacity(0);
|
||||
}
|
||||
|
||||
|
@ -79,13 +79,17 @@ fn execute(
|
||||
|
||||
var users = User.fromReader(allocator, &errc, passwdFile.reader()) catch |err|
|
||||
return fail(errc.wrap("read users"), stderr, err);
|
||||
defer for (users) |*user| user.deinit(allocator);
|
||||
defer allocator.free(users);
|
||||
defer {
|
||||
for (users) |*user| user.deinit(allocator);
|
||||
allocator.free(users);
|
||||
}
|
||||
|
||||
var groups = Group.fromReader(allocator, groupFile.reader()) catch |err|
|
||||
return fail(errc.wrap("read groups"), stderr, err);
|
||||
defer for (groups) |*group| group.deinit(allocator);
|
||||
defer allocator.free(groups);
|
||||
defer {
|
||||
for (groups) |*group| group.deinit(allocator);
|
||||
allocator.free(groups);
|
||||
}
|
||||
|
||||
var corpus = Corpus.init(allocator, users, groups) catch |err|
|
||||
return fail(errc.wrap("init corpus"), stderr, err);
|
||||
@ -203,7 +207,6 @@ test "smoke test" {
|
||||
while (i < corpus.users.len) : (i += 1) {
|
||||
const user = corpus.users.get(i);
|
||||
const line = user.toLine().constSlice();
|
||||
std.debug.print("({d}){s}", .{ line.len, line });
|
||||
_ = try os.write(passwd_fd, line);
|
||||
}
|
||||
os.close(passwd_fd);
|
||||
@ -221,7 +224,6 @@ test "smoke test" {
|
||||
};
|
||||
|
||||
const exit_code = execute(allocator, stdout.writer(), stderr.writer(), args);
|
||||
//if (true) return error.SkipZigTest;
|
||||
try testing.expectEqualStrings("", stderr.items);
|
||||
try testing.expectEqualStrings("total 1664 bytes. groups=5 users=4\n", stderr.items);
|
||||
try testing.expectEqual(@as(u8, 0), exit_code);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user