add new ly error messages. Only try to make path for pam/exe during install when dest_directory is defined + print warning on error.

This commit is contained in:
Kinzie 2024-06-27 04:12:03 +01:00
parent f9d6a3750e
commit cf420b4d83
No known key found for this signature in database
GPG Key ID: EF86FC12BB84F79E
5 changed files with 25 additions and 5 deletions

View File

@ -41,7 +41,7 @@ pub fn build(b: *std.Build) !void {
exe.linkSystemLibrary("xcb");
exe.linkLibC();
// Only fails with ReleaseSafe, so we'll override it.
// HACK: Only fails with ReleaseSafe, so we'll override it.
const translate_c = b.addTranslateC(.{
.root_source_file = .{ .path = "include/termbox2.h" },
.target = target,
@ -151,7 +151,11 @@ fn install_ly(allocator: std.mem.Allocator, install_config: bool) !void {
{
const exe_path = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, "/usr/bin" });
std.fs.cwd().makePath(exe_path) catch {};
if (!std.mem.eql(u8, dest_directory, "")) {
std.fs.cwd().makePath(exe_path) catch {
std.debug.print("warn: {s} already exists as a directory.\n", .{exe_path});
};
}
var executable_dir = std.fs.openDirAbsolute(exe_path, .{}) catch unreachable;
defer executable_dir.close();
@ -194,7 +198,11 @@ fn install_ly(allocator: std.mem.Allocator, install_config: bool) !void {
{
const pam_path = try std.fs.path.join(allocator, &[_][]const u8{ dest_directory, "/etc/pam.d" });
std.fs.cwd().makePath(pam_path) catch {};
if (!std.mem.eql(u8, dest_directory, "")) {
std.fs.cwd().makePath(pam_path) catch {
std.debug.print("warn: {s} already exists as a directory.\n", .{pam_path});
};
}
var pam_dir = std.fs.openDirAbsolute(pam_path, .{}) catch unreachable;
defer pam_dir.close();

View File

@ -6,7 +6,9 @@ err_chdir = failed to open home folder
err_console_dev = failed to access console
err_dgn_oob = log message
err_domain = invalid domain
err_envlist = failed to get envlist
err_hostname = failed to get hostname
err_mcookie = mcookie command failed
err_mlock = failed to lock password memory
err_null = null pointer
err_pam = pam transaction failed
@ -34,6 +36,8 @@ err_unknown = an unknown error occurred
err_user_gid = failed to set user GID
err_user_init = failed to initialize user
err_user_uid = failed to set user UID
err_xauth = xauth command failed
err_xcb_conn = xcb connection failed
err_xsessions_dir = failed to find sessions folder
err_xsessions_open = failed to open sessions folder
insert = insert

View File

@ -348,11 +348,11 @@ pub fn mcookie(cmd: [:0]const u8) ![32]u8 {
const result = std.posix.waitpid(pid, 0);
if (result.status != 0) return error.CommandFailed;
if (result.status != 0) return error.McookieFailed;
var buf: [32]u8 = undefined;
const len = try output.read(&buf);
if (len != 32) return error.UnexpectedLength;
if (len != 32) return error.McookieFailed;
return buf;
}

View File

@ -6,7 +6,9 @@ err_chdir: []const u8 = "failed to open home folder",
err_console_dev: []const u8 = "failed to access console",
err_dgn_oob: []const u8 = "log message",
err_domain: []const u8 = "invalid domain",
err_envlist: []const u8 = "failed to get envlist",
err_hostname: []const u8 = "failed to get hostname",
err_mcookie: []const u8 = "mcookie command failed",
err_mlock: []const u8 = "failed to lock password memory",
err_null: []const u8 = "null pointer",
err_pam: []const u8 = "pam transaction failed",
@ -34,6 +36,8 @@ err_unknown: []const u8 = "an unknown error occurred",
err_user_gid: []const u8 = "failed to set user GID",
err_user_init: []const u8 = "failed to initialize user",
err_user_uid: []const u8 = "failed to set user UID",
err_xauth: []const u8 = "xauth command failed",
err_xcb_conn: []const u8 = "xcb connection failed",
err_xsessions_dir: []const u8 = "failed to find sessions folder",
err_xsessions_open: []const u8 = "failed to open sessions folder",
insert: []const u8 = "insert",

View File

@ -639,6 +639,10 @@ pub fn main() !void {
fn getAuthErrorMsg(err: anyerror, lang: Lang) []const u8 {
return switch (err) {
error.GetPasswordNameFailed => lang.err_pwnam,
error.GetEnvListFailed => lang.err_envlist,
error.XauthFailed => lang.err_xauth,
error.McookieFailed => lang.err_mcookie,
error.XcbConnectionFailed => lang.err_xcb_conn,
error.GroupInitializationFailed => lang.err_user_init,
error.SetUserGidFailed => lang.err_user_gid,
error.SetUserUidFailed => lang.err_user_uid,