Merge #162246: build-support/writeTextFile: fix for names with spaces

This commit is contained in:
piegames 2022-03-10 20:16:50 +01:00 committed by GitHub
commit 99391da078
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 39 additions and 9 deletions

View File

@ -34,11 +34,6 @@
, extraConfig ? {} # Additional values to be added literally to the final item, e.g. vendor extensions
}:
let
# FIXME: workaround until https://github.com/NixOS/nixpkgs/pull/162246 lands
cleanName = if lib.hasInfix " " name
then throw "makeDesktopItem: name must not contain spaces!"
else name;
# There are multiple places in the FDO spec that make "boolean" values actually tristate,
# e.g. StartupNotify, where "unset" is literally defined as "do something reasonable".
# So, handle null values separately.
@ -116,8 +111,8 @@ let
content = [ mainSectionRendered ] ++ actionsRendered;
in
writeTextFile {
name = "${cleanName}.desktop";
destination = "/share/applications/${cleanName}.desktop";
name = "${name}.desktop";
destination = "/share/applications/${name}.desktop";
text = builtins.concatStringsSep "\n" content;
checkPhase = "${buildPackages.desktop-file-utils}/bin/desktop-file-validate $target";
checkPhase = ''${buildPackages.desktop-file-utils}/bin/desktop-file-validate "$target"'';
}

View File

@ -121,7 +121,7 @@ rec {
allowSubstitutes = false;
}
''
target=$out${destination}
target=$out${lib.escapeShellArg destination}
mkdir -p "$(dirname "$target")"
if [ -e "$textPath" ]; then

View File

@ -0,0 +1,34 @@
{ writeTextFile }:
let
veryWeirdName = ''here's a name with some "bad" characters, like spaces and quotes'';
in writeTextFile {
name = "weird-names";
destination = "/etc/${veryWeirdName}";
text = ''passed!'';
checkPhase = ''
# intentionally hardcode everything here, to make sure
# Nix does not mess with file paths
name="here's a name with some \"bad\" characters, like spaces and quotes"
fullPath="$out/etc/$name"
if [ -f "$fullPath" ]; then
echo "[PASS] File exists!"
else
echo "[FAIL] File was not created at expected path!"
exit 1
fi
content=$(<"$fullPath")
expected="passed!"
if [ "$content" = "$expected" ]; then
echo "[PASS] Contents match!"
else
echo "[FAIL] File contents don't match!"
echo " Expected: $expected"
echo " Got: $content"
exit 2
fi
'';
}

View File

@ -59,6 +59,7 @@ with pkgs;
trivial-builders = recurseIntoAttrs {
writeStringReferencesToFile = callPackage ../build-support/trivial-builders/test/writeStringReferencesToFile.nix {};
writeTextFile = callPackage ../build-support/trivial-builders/test/write-text-file.nix {};
references = callPackage ../build-support/trivial-builders/test/references.nix {};
overriding = callPackage ../build-support/trivial-builders/test-overriding.nix {};
concat = callPackage ../build-support/trivial-builders/test/concat-test.nix {};