summaryrefslogtreecommitdiff
path: root/lib/fileset/tests.sh
diff options
context:
space:
mode:
authorSilvan Mosberger <silvan.mosberger@tweag.io>2023-09-14 21:40:17 +0200
committerSilvan Mosberger <silvan.mosberger@tweag.io>2023-09-21 00:21:01 +0200
commite04e40d05e5d959e30188d62c76e3dfb5cb26b16 (patch)
tree5b5b14b9992825195020a490376c43487d6f7828 /lib/fileset/tests.sh
parentlib.fileset: Various updates relating to union/unions (diff)
downloadnixpkgs-e04e40d05e5d959e30188d62c76e3dfb5cb26b16.tar.gz
lib.fileset: Optimise tests
Previously a lot of processes were used, slowing it down considerably the more files were tested
Diffstat (limited to 'lib/fileset/tests.sh')
-rwxr-xr-xlib/fileset/tests.sh22
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/fileset/tests.sh b/lib/fileset/tests.sh
index 69ce29bbbfb3..cee93615d56f 100755
--- a/lib/fileset/tests.sh
+++ b/lib/fileset/tests.sh
@@ -124,18 +124,19 @@ checkFileset() (
local fileset=$1
# Process the tree into separate arrays for included paths, excluded paths and excluded files.
- # Also create all the paths in the local directory
local -a included=()
local -a excluded=()
local -a excludedFiles=()
+ # Track which paths need to be created
+ local -a dirsToCreate=()
+ local -a filesToCreate=()
for p in "${!tree[@]}"; do
# If keys end with a `/` we treat them as directories, otherwise files
if [[ "$p" =~ /$ ]]; then
- mkdir -p "$p"
+ dirsToCreate+=("$p")
isFile=
else
- mkdir -p "$(dirname "$p")"
- touch "$p"
+ filesToCreate+=("$p")
isFile=1
fi
case "${tree[$p]}" in
@@ -153,6 +154,19 @@ checkFileset() (
esac
done
+ # Create all the necessary paths.
+ # This is done with only a fixed number of processes,
+ # in order to not be too slow
+ # Though this does mean we're a bit limited with how many files can be created
+ if (( ${#dirsToCreate[@]} != 0 )); then
+ mkdir -p "${dirsToCreate[@]}"
+ fi
+ if (( ${#filesToCreate[@]} != 0 )); then
+ readarray -d '' -t parentsToCreate < <(dirname -z "${filesToCreate[@]}")
+ mkdir -p "${parentsToCreate[@]}"
+ touch "${filesToCreate[@]}"
+ fi
+
# Start inotifywait in the background to monitor all excluded files (if any)
if [[ -n "$canMonitorFiles" ]] && (( "${#excludedFiles[@]}" != 0 )); then
coproc watcher {