From f02efa3fe3934deb0fb5aafc6a05bf8bec4c523c Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Tue, 4 Apr 2023 21:11:28 +0100 Subject: [PATCH] refactor --- pkgs/pseudofile/default.nix | 46 +++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 22 deletions(-) diff --git a/pkgs/pseudofile/default.nix b/pkgs/pseudofile/default.nix index 336364e..bdde354 100644 --- a/pkgs/pseudofile/default.nix +++ b/pkgs/pseudofile/default.nix @@ -12,30 +12,32 @@ let msg; l = mapAttrsToList - (filename: attrs: + (filename: { + type ? "f" + , mode ? null + , target ? null + , contents ? null + , file ? null + , major ? null + , minor ? null + , subtype ? null + }: let - attrs' = {type = "f"; } // attrs; - mode = if attrs ? mode then attrs.mode else - (if attrs'.type == "d" then "0755" else "0644"); - line = "${prefix}/${filename} ${attrs'.type} ${mode} 0 0"; + mode' = if mode != null then mode else + (if type == "d" then "0755" else "0644"); + pathname = "${prefix}/${filename}"; + line = "${pathname} ${type} ${mode'} 0 0"; in - if attrs'.type == "f" then - "${line} echo -n \"${qprint attrs'.file}\" |qprint -d" - else if attrs'.type == "d" then - (visit "${prefix}/${filename}" attrs.contents) + - "\n" + line - else if attrs'.type == "c" then - with attrs'; "${line} ${major} ${minor}" - else if attrs'.type == "b" then - with attrs'; "${line} ${major} ${minor}" - else if attrs'.type == "s" then - "${line} ${attrs'.target}" - else if attrs'.type == "l" then - "${prefix}/${filename} l ${attrs'.target}" - else if attrs'.type == "i" then - "${line} ${attrs.subtype}" - else - line) + if type == "f" then + "${line} echo -n \"${qprint file}\" |qprint -d" + else if type == "d" then + (visit pathname contents) + "\n" + line + else if type == "c" then "${line} ${major} ${minor}" + else if type == "b" then "${line} ${major} ${minor}" + else if type == "s" then "${line} ${target}" + else if type == "l" then "${pathname} l ${target}" + else if type == "i" then "${line} ${subtype}" + else line) attrset; in builtins.concatStringsSep "\n" l; in {