diff options
author | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-09-14 21:40:17 +0200 |
---|---|---|
committer | Silvan Mosberger <silvan.mosberger@tweag.io> | 2023-09-21 00:21:01 +0200 |
commit | e04e40d05e5d959e30188d62c76e3dfb5cb26b16 (patch) | |
tree | 5b5b14b9992825195020a490376c43487d6f7828 /lib/fileset | |
parent | c5ae093f13ed2a2a1b9b82331b5cfccad1fb7bdd (diff) |
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')
-rwxr-xr-x | lib/fileset/tests.sh | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/fileset/tests.sh b/lib/fileset/tests.sh index 69ce29bbbfb31..cee93615d56f8 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 { |