mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-10 03:23:29 +03:00
lib/types: check paths in pathWith with hasStorePathPrefix (#387304)
This commit is contained in:
commit
013beed1db
4 changed files with 18 additions and 2 deletions
|
@ -165,7 +165,7 @@ let
|
||||||
# This is a workaround for https://github.com/NixOS/nix/issues/12361 which
|
# This is a workaround for https://github.com/NixOS/nix/issues/12361 which
|
||||||
# was needed during the experimental phase of ca-derivations and should be
|
# was needed during the experimental phase of ca-derivations and should be
|
||||||
# removed once the issue has been resolved.
|
# removed once the issue has been resolved.
|
||||||
|| match "[0-9a-z]{52}" (head components) != null;
|
|| components != [ ] && match "[0-9a-z]{52}" (head components) != null;
|
||||||
|
|
||||||
in
|
in
|
||||||
# No rec! Add dependencies on this file at the top.
|
# No rec! Add dependencies on this file at the top.
|
||||||
|
|
|
@ -110,6 +110,12 @@ let
|
||||||
expected = false;
|
expected = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Root path (empty path components list)
|
||||||
|
testHasStorePathPrefixRoot = {
|
||||||
|
expr = hasStorePathPrefix /.;
|
||||||
|
expected = false;
|
||||||
|
};
|
||||||
|
|
||||||
testHasStorePathPrefixExample1 = {
|
testHasStorePathPrefixExample1 = {
|
||||||
expr = hasStorePathPrefix (storeDirPath + "/nvl9ic0pj1fpyln3zaqrf4cclbqdfn1j-foo/bar/baz");
|
expr = hasStorePathPrefix (storeDirPath + "/nvl9ic0pj1fpyln3zaqrf4cclbqdfn1j-foo/bar/baz");
|
||||||
expected = true;
|
expected = true;
|
||||||
|
|
|
@ -58,6 +58,9 @@ in
|
||||||
pathInStore.ok1 = "${storeDir}/0lz9p8xhf89kb1c1kk6jxrzskaiygnlh-bash-5.2-p15.drv";
|
pathInStore.ok1 = "${storeDir}/0lz9p8xhf89kb1c1kk6jxrzskaiygnlh-bash-5.2-p15.drv";
|
||||||
pathInStore.ok2 = "${storeDir}/0fb3ykw9r5hpayd05sr0cizwadzq1d8q-bash-5.2-p15";
|
pathInStore.ok2 = "${storeDir}/0fb3ykw9r5hpayd05sr0cizwadzq1d8q-bash-5.2-p15";
|
||||||
pathInStore.ok3 = "${storeDir}/0fb3ykw9r5hpayd05sr0cizwadzq1d8q-bash-5.2-p15/bin/bash";
|
pathInStore.ok3 = "${storeDir}/0fb3ykw9r5hpayd05sr0cizwadzq1d8q-bash-5.2-p15/bin/bash";
|
||||||
|
pathInStore.ok4 = "/1121rp0gvr1qya7hvy925g5kjwg66acz6sn1ra1hca09f1z5dsab"; # CA derivation
|
||||||
|
pathInStore.ok5 = "/1121rp0gvr1qya7hvy925g5kjwg66acz6sn1ra1hca09f1z5dsab/bin/bash"; # CA derivation
|
||||||
|
pathInStore.ok6 = /1121rp0gvr1qya7hvy925g5kjwg66acz6sn1ra1hca09f1z5dsab; # CA derivation, path type
|
||||||
pathInStore.bad1 = "";
|
pathInStore.bad1 = "";
|
||||||
pathInStore.bad2 = "${storeDir}";
|
pathInStore.bad2 = "${storeDir}";
|
||||||
pathInStore.bad3 = "${storeDir}/";
|
pathInStore.bad3 = "${storeDir}/";
|
||||||
|
|
|
@ -678,7 +678,14 @@ let
|
||||||
check =
|
check =
|
||||||
x:
|
x:
|
||||||
let
|
let
|
||||||
isInStore = builtins.match "${builtins.storeDir}/[^.].*" (toString x) != null;
|
isInStore = lib.path.hasStorePathPrefix (
|
||||||
|
if builtins.isPath x then
|
||||||
|
x
|
||||||
|
# Discarding string context is necessary to convert the value to
|
||||||
|
# a path and safe as the result is never used in any derivation.
|
||||||
|
else
|
||||||
|
/. + builtins.unsafeDiscardStringContext x
|
||||||
|
);
|
||||||
isAbsolute = builtins.substring 0 1 (toString x) == "/";
|
isAbsolute = builtins.substring 0 1 (toString x) == "/";
|
||||||
isExpectedType = (
|
isExpectedType = (
|
||||||
if inStore == null || inStore then isStringLike x else isString x # Do not allow a true path, which could be copied to the store later on.
|
if inStore == null || inStore then isStringLike x else isString x # Do not allow a true path, which could be copied to the store later on.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue