+
+ # Wait for background jobs to finish
+ wait
+
+ echo "Removing empty diffs"
+ # TIF cleanup loop for images which have no diff
+ while IFS= read -r -d $'\0' FILE; do
+ ( FILE_COLOURS=$(identify -quiet -format '%k' "${OSSV_DIFF_NAME}/${FILE}")
+ if [ "$FILE_COLOURS" -lt "2" ]; then
+ rm -f "${OSSV_DIFF_NAME}/${FILE}"
+ touch "${OSSV_DIFF_NAME}/${FILE}.skip"
+ fi ) &
+
+ # Check how many background processes and wait if exceed
+ running=($(jobs -rp))
+ while [ ${#running[@]} -ge 16 ] ; do
+ sleep 1 # this is not optimal, but you can't use wait here
+ running=($(jobs -rp))
+ done
+ done < <(find "${OSSV_DIFF_NAME}" -maxdepth 1 -name '*.tif' -size -180000c -printf '%f\0')
+ # Wait for background jobs to finish
+ wait
+ if [ ! -f "ossv-${OSSV_DIFF_NAME}-combined.vrt" ]; then
+ gdalbuildvrt -resolution highest -hidenodata "ossv-${OSSV_DIFF_NAME}-combined.vrt" ${OSSV_DIFF_NAME}/*.tif
+ fi