realistic bugfixes
This commit is contained in:
parent
2e4229d613
commit
c39f89d995
|
@ -51,7 +51,7 @@ pub fn build(b: *zbs.Builder) void {
|
|||
cmph.addIncludeDir("include/deps/cmph");
|
||||
|
||||
{
|
||||
const exe = b.addExecutable("turbo-unix2db", "src/unix2db/main.zig");
|
||||
const exe = b.addExecutable("turbo-unix2db", "src/unix2db.zig");
|
||||
exe.setTarget(target);
|
||||
exe.setBuildMode(mode);
|
||||
addCmphDeps(exe, cmph);
|
||||
|
|
|
@ -11,6 +11,7 @@ const ArrayListUnmanaged = std.ArrayListUnmanaged;
|
|||
|
||||
const User = @import("User.zig");
|
||||
const Group = @import("Group.zig");
|
||||
const ErrCtx = @import("ErrCtx.zig");
|
||||
|
||||
pub const Corpus = @This();
|
||||
|
||||
|
@ -33,6 +34,7 @@ pub fn init(
|
|||
baseAllocator: Allocator,
|
||||
usersConst: []const User,
|
||||
groupsConst: []const Group,
|
||||
err: *ErrCtx,
|
||||
) error{ OutOfMemory, InvalidUtf8, Duplicate, NotFound, TooMany }!Corpus {
|
||||
if (usersConst.len >= math.maxInt(u32)) return error.TooMany;
|
||||
if (groupsConst.len >= math.maxInt(u32)) return error.TooMany;
|
||||
|
@ -43,6 +45,7 @@ pub fn init(
|
|||
|
||||
var groups_arr = try allocator.alloc(Group, groupsConst.len);
|
||||
var users_arr = try allocator.alloc(User, usersConst.len);
|
||||
|
||||
var getgr_bufsize: usize = 0;
|
||||
for (groupsConst) |*group, i| {
|
||||
groups_arr[i] = try group.clone(allocator);
|
||||
|
@ -99,7 +102,13 @@ pub fn init(
|
|||
members.len += 1;
|
||||
members[members.len - 1] = user_idx;
|
||||
try user2groups[user_idx].append(allocator, @intCast(u32, i));
|
||||
} else return error.NotFound;
|
||||
} else {
|
||||
return err.returnf(
|
||||
"user '{s}' not found, member of group '{s}'",
|
||||
.{ member_name, groups_arr[i].name },
|
||||
error.NotFound,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
group2users[i] = members;
|
||||
|
@ -145,10 +154,10 @@ fn cmpUser(_: void, a: User, b: User) bool {
|
|||
}
|
||||
|
||||
// a is a prefix of b. It is thus shorter.
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
// b is a prefix of a
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
fn cmpGroup(_: void, a: Group, b: Group) bool {
|
||||
|
|
|
@ -93,7 +93,8 @@ pub fn fromReader(allocator: Allocator, reader: anytype) FromReaderError![]Group
|
|||
|
||||
var members_it = mem.split(u8, members_commas, ",");
|
||||
while (members_it.next()) |member|
|
||||
try member_ptrs.append(member);
|
||||
if (member.len != 0)
|
||||
try member_ptrs.append(member);
|
||||
|
||||
const group = try init(allocator, gid, name, member_ptrs.items);
|
||||
try groups.append(group);
|
||||
|
|
|
@ -12,7 +12,9 @@ test "turbonss test suite" {
|
|||
_ = @import("PackedUser.zig");
|
||||
_ = @import("padding.zig");
|
||||
_ = @import("shell.zig");
|
||||
_ = @import("unix2db/main.zig");
|
||||
_ = @import("User.zig");
|
||||
_ = @import("validate.zig");
|
||||
|
||||
// main
|
||||
_ = @import("unix2db.zig");
|
||||
}
|
||||
|
|
|
@ -7,12 +7,12 @@ const ArrayList = std.ArrayList;
|
|||
const Allocator = std.mem.Allocator;
|
||||
const GeneralPurposeAllocator = std.heap.GeneralPurposeAllocator;
|
||||
|
||||
const flags = @import("../flags.zig");
|
||||
const User = @import("../User.zig");
|
||||
const Group = @import("../Group.zig");
|
||||
const Corpus = @import("../Corpus.zig");
|
||||
const DB = @import("../DB.zig");
|
||||
const ErrCtx = @import("../ErrCtx.zig");
|
||||
const flags = @import("flags.zig");
|
||||
const User = @import("User.zig");
|
||||
const Group = @import("Group.zig");
|
||||
const Corpus = @import("Corpus.zig");
|
||||
const DB = @import("DB.zig");
|
||||
const ErrCtx = @import("ErrCtx.zig");
|
||||
|
||||
const usage =
|
||||
\\usage: turbonss-unix2db [options]
|
||||
|
@ -93,7 +93,7 @@ fn execute(
|
|||
allocator.free(groups);
|
||||
}
|
||||
|
||||
var corpus = Corpus.init(allocator, users, groups) catch |err|
|
||||
var corpus = Corpus.init(allocator, users, groups, &errc) catch |err|
|
||||
return fail(errc.wrap("init corpus"), stderr, err);
|
||||
|
||||
defer corpus.deinit();
|
Loading…
Reference in New Issue