nixos/lib/utils: partially apply hasPrefix
This commit is contained in:
+5
-3
@@ -43,6 +43,8 @@ in
|
||||
|
||||
let
|
||||
hasSlashSuffix = hasSuffix "/";
|
||||
isAbsolute = hasPrefix "/";
|
||||
|
||||
# normalisePath adds a slash at the end of the path if it didn't already
|
||||
# have one.
|
||||
#
|
||||
@@ -62,6 +64,7 @@ let
|
||||
mountPoint = normalisePath mount.mountPoint;
|
||||
depends = map normalisePath mount.depends;
|
||||
};
|
||||
|
||||
utils = rec {
|
||||
|
||||
# Copy configuration files to avoid having the entire sources in the system closure
|
||||
@@ -115,7 +118,6 @@ let
|
||||
in
|
||||
s:
|
||||
let
|
||||
isAbsolute = hasPrefix "/" s;
|
||||
# path_simplify(): collapse duplicate slashes and drop "." components.
|
||||
rawComponents = filter (c: c != "" && c != ".") (splitString "/" s);
|
||||
# systemd accepts ".." only where it is redundant: a leading ".." in an
|
||||
@@ -128,7 +130,7 @@ let
|
||||
acc: c:
|
||||
if c == ".." then
|
||||
# A leading ".." in an absolute path is the only redundant case.
|
||||
if isAbsolute && acc.components == [ ] then acc else acc // { normalized = false; }
|
||||
if isAbsolute s && acc.components == [ ] then acc else acc // { normalized = false; }
|
||||
else
|
||||
acc // { components = acc.components ++ [ c ]; }
|
||||
)
|
||||
@@ -144,7 +146,7 @@ let
|
||||
else if simplified.components != [ ] then
|
||||
concatStringsSep "/" simplified.components
|
||||
# The root directory, and - matching systemd-escape - the empty string.
|
||||
else if isAbsolute || s == "" then
|
||||
else if isAbsolute s || s == "" then
|
||||
"/"
|
||||
# A relative path that reduces to nothing (e.g. "."), which has no
|
||||
# valid escaping.
|
||||
|
||||
Reference in New Issue
Block a user