refine my errors

This commit is contained in:
Squibid 2025-12-06 03:53:03 -05:00
parent 27ace62925
commit 8cf6029872
Signed by: squibid
GPG key ID: BECE5684D3C4005D
2 changed files with 9 additions and 13 deletions

View file

@ -4,41 +4,37 @@ const std = @import("std");
const gpa = std.heap.page_allocator;
const NixStoreError = error{
Failure,
};
pub fn add(path: []const u8) NixStoreError![]const u8 {
pub fn add(path: []const u8) error{Failure}![]const u8 {
const res = std.process.Child.run(.{
.allocator = gpa,
.argv = &[_][]const u8{ "nix", "store", "add", path },
}) catch return NixStoreError.Failure;
}) catch return error.Failure;
return res.stdout[0 .. res.stdout.len - 1]; // to chop off the \n
}
pub fn realize(store_path: []const u8) NixStoreError!void {
pub fn realize(store_path: []const u8) error{Failure}!void {
_ = std.process.Child.run(.{
.allocator = gpa,
.argv = &[_][]const u8{ "nix-store", "--realize", store_path },
}) catch return NixStoreError.Failure;
}) catch return error.Failure;
return;
}
pub fn root(store_path: []const u8, root_path: []const u8) NixStoreError!void {
pub fn root(store_path: []const u8, root_path: []const u8) error{Failure}!void {
_ = std.process.Child.run(.{
.allocator = gpa,
.argv = &[_][]const u8{ "nix-store", "--add-root", root_path, "--indirect", store_path },
}) catch return NixStoreError.Failure;
}) catch return error.Failure;
return;
}
pub fn delete(store_path: []const u8) NixStoreError!void {
pub fn delete(store_path: []const u8) error{Failure}!void {
_ = std.process.Child.run(.{
.allocator = gpa,
.argv = &[_][]const u8{ "nix", "store", "delete", store_path },
}) catch {
return NixStoreError.Failure;
return error.Failure;
};
return;
}

View file

@ -102,7 +102,7 @@ pub fn main() !void {
// delete the old nix store path
if (dest_old_store_path) |path| {
std.log.info("deleting old store path: {s}", .{path});
NixStore.delete(path) catch |err| if (err == error.Failure) return err;
try NixStore.delete(path);
}
}