lib: only readDir if path exists with safeReadDir
This commit is contained in:
parent
f14dcdaf78
commit
3d1501c384
|
@ -40,4 +40,6 @@ rec {
|
|||
lib.isDerivation v && !meta.broken && builtins.elem system platforms);
|
||||
in
|
||||
lib.filterAttrs filter packages;
|
||||
|
||||
safeReadDir = path: lib.optionalAttrs (builtins.pathExists path) (builtins.readDir path);
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ lib.makeExtensible (final:
|
|||
lists = callLibs ./lists.nix;
|
||||
strings = callLibs ./strings.nix;
|
||||
|
||||
inherit (attrs) mapFilterAttrs genAttrs'
|
||||
inherit (attrs) mapFilterAttrs genAttrs' safeReadDir
|
||||
pathsToImportedAttrs concatAttrs filterPackages;
|
||||
inherit (lists) pathsIn;
|
||||
inherit (strings) rgxToString;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{ lib, ... }:
|
||||
{ lib, dev, ... }:
|
||||
|
||||
let mkProfileAttrs =
|
||||
/**
|
||||
|
@ -16,7 +16,7 @@ let mkProfileAttrs =
|
|||
let
|
||||
imports =
|
||||
let
|
||||
files = builtins.readDir dir;
|
||||
files = dev.safeReadDir dir;
|
||||
|
||||
p = n: v:
|
||||
v == "directory"
|
||||
|
|
|
@ -9,4 +9,4 @@ dev.mapFilterAttrs
|
|||
let name = lib.removeSuffix ".nix" n; in lib.nameValuePair (name) (_import name)
|
||||
else
|
||||
lib.nameValuePair ("") (null))
|
||||
(builtins.readDir dir)
|
||||
(dev.safeReadDir dir)
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
{ lib, ... }:
|
||||
{ lib, dev, ... }:
|
||||
{
|
||||
pathsIn = dir:
|
||||
let
|
||||
fullPath = name: "${toString dir}/${name}";
|
||||
in
|
||||
map fullPath (lib.attrNames (lib.optionalAttrs
|
||||
(builtins.pathExists dir) (builtins.readDir dir)));
|
||||
map fullPath (lib.attrNames (dev.safeReadDir dir));
|
||||
}
|
||||
|
|
|
@ -69,6 +69,14 @@ lib.runTests {
|
|||
(rgxToString "hat" "foohatbar" == "hat")
|
||||
];
|
||||
|
||||
testSafeReadDir = {
|
||||
expr = safeReadDir "${self}/tests/profiles" // safeReadDir "${self}/nonexistentdir";
|
||||
expected = {
|
||||
foo = "directory";
|
||||
t = "directory";
|
||||
};
|
||||
};
|
||||
|
||||
testSuites =
|
||||
let
|
||||
profiles = os.mkProfileAttrs (toString ./profiles);
|
||||
|
|
Loading…
Reference in a new issue