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");
|
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.setTarget(target);
|
||||||
exe.setBuildMode(mode);
|
exe.setBuildMode(mode);
|
||||||
addCmphDeps(exe, cmph);
|
addCmphDeps(exe, cmph);
|
||||||
|
@ -11,6 +11,7 @@ const ArrayListUnmanaged = std.ArrayListUnmanaged;
|
|||||||
|
|
||||||
const User = @import("User.zig");
|
const User = @import("User.zig");
|
||||||
const Group = @import("Group.zig");
|
const Group = @import("Group.zig");
|
||||||
|
const ErrCtx = @import("ErrCtx.zig");
|
||||||
|
|
||||||
pub const Corpus = @This();
|
pub const Corpus = @This();
|
||||||
|
|
||||||
@ -33,6 +34,7 @@ pub fn init(
|
|||||||
baseAllocator: Allocator,
|
baseAllocator: Allocator,
|
||||||
usersConst: []const User,
|
usersConst: []const User,
|
||||||
groupsConst: []const Group,
|
groupsConst: []const Group,
|
||||||
|
err: *ErrCtx,
|
||||||
) error{ OutOfMemory, InvalidUtf8, Duplicate, NotFound, TooMany }!Corpus {
|
) error{ OutOfMemory, InvalidUtf8, Duplicate, NotFound, TooMany }!Corpus {
|
||||||
if (usersConst.len >= math.maxInt(u32)) return error.TooMany;
|
if (usersConst.len >= math.maxInt(u32)) return error.TooMany;
|
||||||
if (groupsConst.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 groups_arr = try allocator.alloc(Group, groupsConst.len);
|
||||||
var users_arr = try allocator.alloc(User, usersConst.len);
|
var users_arr = try allocator.alloc(User, usersConst.len);
|
||||||
|
|
||||||
var getgr_bufsize: usize = 0;
|
var getgr_bufsize: usize = 0;
|
||||||
for (groupsConst) |*group, i| {
|
for (groupsConst) |*group, i| {
|
||||||
groups_arr[i] = try group.clone(allocator);
|
groups_arr[i] = try group.clone(allocator);
|
||||||
@ -99,7 +102,13 @@ pub fn init(
|
|||||||
members.len += 1;
|
members.len += 1;
|
||||||
members[members.len - 1] = user_idx;
|
members[members.len - 1] = user_idx;
|
||||||
try user2groups[user_idx].append(allocator, @intCast(u32, i));
|
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;
|
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.
|
// a is a prefix of b. It is thus shorter.
|
||||||
return false;
|
return true;
|
||||||
}
|
}
|
||||||
// b is a prefix of a
|
// b is a prefix of a
|
||||||
return true;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
fn cmpGroup(_: void, a: Group, b: Group) bool {
|
fn cmpGroup(_: void, a: Group, b: Group) bool {
|
||||||
|
@ -93,6 +93,7 @@ pub fn fromReader(allocator: Allocator, reader: anytype) FromReaderError![]Group
|
|||||||
|
|
||||||
var members_it = mem.split(u8, members_commas, ",");
|
var members_it = mem.split(u8, members_commas, ",");
|
||||||
while (members_it.next()) |member|
|
while (members_it.next()) |member|
|
||||||
|
if (member.len != 0)
|
||||||
try member_ptrs.append(member);
|
try member_ptrs.append(member);
|
||||||
|
|
||||||
const group = try init(allocator, gid, name, member_ptrs.items);
|
const group = try init(allocator, gid, name, member_ptrs.items);
|
||||||
|
@ -12,7 +12,9 @@ test "turbonss test suite" {
|
|||||||
_ = @import("PackedUser.zig");
|
_ = @import("PackedUser.zig");
|
||||||
_ = @import("padding.zig");
|
_ = @import("padding.zig");
|
||||||
_ = @import("shell.zig");
|
_ = @import("shell.zig");
|
||||||
_ = @import("unix2db/main.zig");
|
|
||||||
_ = @import("User.zig");
|
_ = @import("User.zig");
|
||||||
_ = @import("validate.zig");
|
_ = @import("validate.zig");
|
||||||
|
|
||||||
|
// main
|
||||||
|
_ = @import("unix2db.zig");
|
||||||
}
|
}
|
||||||
|
@ -7,12 +7,12 @@ const ArrayList = std.ArrayList;
|
|||||||
const Allocator = std.mem.Allocator;
|
const Allocator = std.mem.Allocator;
|
||||||
const GeneralPurposeAllocator = std.heap.GeneralPurposeAllocator;
|
const GeneralPurposeAllocator = std.heap.GeneralPurposeAllocator;
|
||||||
|
|
||||||
const flags = @import("../flags.zig");
|
const flags = @import("flags.zig");
|
||||||
const User = @import("../User.zig");
|
const User = @import("User.zig");
|
||||||
const Group = @import("../Group.zig");
|
const Group = @import("Group.zig");
|
||||||
const Corpus = @import("../Corpus.zig");
|
const Corpus = @import("Corpus.zig");
|
||||||
const DB = @import("../DB.zig");
|
const DB = @import("DB.zig");
|
||||||
const ErrCtx = @import("../ErrCtx.zig");
|
const ErrCtx = @import("ErrCtx.zig");
|
||||||
|
|
||||||
const usage =
|
const usage =
|
||||||
\\usage: turbonss-unix2db [options]
|
\\usage: turbonss-unix2db [options]
|
||||||
@ -93,7 +93,7 @@ fn execute(
|
|||||||
allocator.free(groups);
|
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);
|
return fail(errc.wrap("init corpus"), stderr, err);
|
||||||
|
|
||||||
defer corpus.deinit();
|
defer corpus.deinit();
|
Loading…
Reference in New Issue
Block a user