Skip to content

Commit 67cd5db

Browse files
authored
fix: Avoid pipe to head on find (#1197)
1 parent 995d5ea commit 67cd5db

File tree

2 files changed

+21
-21
lines changed

2 files changed

+21
-21
lines changed

src/define.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,7 +1215,7 @@ addFolder() {
12151215
cp -Lr "$folder/." "$dest" || return 1
12161216

12171217
local file
1218-
file=$(find "$dest" -maxdepth 1 -type f -iname install.bat | head -n 1)
1218+
file=$(find "$dest" -maxdepth 1 -type f -iname install.bat -print -quit)
12191219
[ -f "$file" ] && unix2dos -q "$file"
12201220

12211221
return 0
@@ -1310,7 +1310,7 @@ prepareInstall() {
13101310
fi
13111311

13121312
local pid file setup
1313-
setup=$(find "$target" -maxdepth 1 -type f -iname setupp.ini | head -n 1)
1313+
setup=$(find "$target" -maxdepth 1 -type f -iname setupp.ini -print -quit)
13141314

13151315
if [ -n "$setup" ]; then
13161316

@@ -1606,20 +1606,20 @@ detectLegacy() {
16061606
local dir="$1"
16071607
local find find2
16081608

1609-
find=$(find "$dir" -maxdepth 1 -type d -iname win95 | head -n 1)
1609+
find=$(find "$dir" -maxdepth 1 -type d -iname win95 -print -quit)
16101610
[ -n "$find" ] && DETECTED="win95" && return 0
16111611

1612-
find=$(find "$dir" -maxdepth 1 -type d -iname win98 | head -n 1)
1612+
find=$(find "$dir" -maxdepth 1 -type d -iname win98 -print -quit)
16131613
[ -n "$find" ] && DETECTED="win98" && return 0
16141614

1615-
find=$(find "$dir" -maxdepth 1 -type d -iname win9x | head -n 1)
1615+
find=$(find "$dir" -maxdepth 1 -type d -iname win9x -print -quit)
16161616
[ -n "$find" ] && DETECTED="win9x" && return 0
16171617

1618-
find=$(find "$dir" -maxdepth 1 -type f -iname cdrom_nt.5 | head -n 1)
1618+
find=$(find "$dir" -maxdepth 1 -type f -iname cdrom_nt.5 -print -quit)
16191619
[ -n "$find" ] && DETECTED="win2k" && return 0
16201620

1621-
find=$(find "$dir" -maxdepth 1 -type d -iname win51 | head -n 1)
1622-
find2=$(find "$dir" -maxdepth 1 -type f -iname setupxp.htm | head -n 1)
1621+
find=$(find "$dir" -maxdepth 1 -type d -iname win51 -print -quit)
1622+
find2=$(find "$dir" -maxdepth 1 -type f -iname setupxp.htm -print -quit)
16231623

16241624
if [ -n "$find" ] || [ -n "$find2" ] || [ -f "$dir/WIN51AP" ] || [ -f "$dir/WIN51IC" ]; then
16251625
[ -d "$dir/AMD64" ] && DETECTED="winxpx64" && return 0

src/install.sh

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ abortInstall() {
201201
[[ "${iso,,}" == *".esd" ]] && exit 60
202202
[[ "${UNPACK:-}" == [Yy1]* ]] && exit 60
203203

204-
efi=$(find "$dir" -maxdepth 1 -type d -iname efi | head -n 1)
204+
efi=$(find "$dir" -maxdepth 1 -type d -iname efi -print -quit)
205205

206206
if [ -z "$efi" ]; then
207207
[[ "${PLATFORM,,}" == "x64" ]] && BOOT_MODE="windows_legacy"
@@ -230,17 +230,17 @@ detectCustom() {
230230

231231
CUSTOM=""
232232

233-
dir=$(find / -maxdepth 1 -type d -iname "$fname" | head -n 1)
234-
[ ! -d "$dir" ] && dir=$(find "$STORAGE" -maxdepth 1 -type d -iname "$fname" | head -n 1)
233+
dir=$(find / -maxdepth 1 -type d -iname "$fname" -print -quit)
234+
[ ! -d "$dir" ] && dir=$(find "$STORAGE" -maxdepth 1 -type d -iname "$fname" -print -quit)
235235

236236
if [ -d "$dir" ]; then
237237
if ! hasDisk || [ ! -f "$boot" ]; then
238238
error "The bind $dir maps to a file that does not exist!" && return 1
239239
fi
240240
fi
241241

242-
file=$(find / -maxdepth 1 -type f -iname "$fname" | head -n 1)
243-
[ ! -s "$file" ] && file=$(find "$STORAGE" -maxdepth 1 -type f -iname "$fname" | head -n 1)
242+
file=$(find / -maxdepth 1 -type f -iname "$fname" -print -quit)
243+
[ ! -s "$file" ] && file=$(find "$STORAGE" -maxdepth 1 -type f -iname "$fname" -print -quit)
244244

245245
if [ ! -s "$file" ] && [[ "${VERSION,,}" != "http"* ]]; then
246246
base=$(basename "$VERSION")
@@ -396,7 +396,7 @@ extractImage() {
396396

397397
else
398398

399-
file=$(find "$dir" -maxdepth 1 -type f -iname "*.iso" | head -n 1)
399+
file=$(find "$dir" -maxdepth 1 -type f -iname "*.iso" -print -quit)
400400

401401
if [ -z "$file" ]; then
402402
error "Failed to find any .iso file in archive!" && return 1
@@ -591,14 +591,14 @@ detectImage() {
591591
fi
592592

593593
local src wim info
594-
src=$(find "$dir" -maxdepth 1 -type d -iname sources | head -n 1)
594+
src=$(find "$dir" -maxdepth 1 -type d -iname sources -print -quit)
595595

596596
if [ ! -d "$src" ]; then
597597
warn "failed to locate 'sources' folder in ISO image, $FB" && return 1
598598
fi
599599

600-
wim=$(find "$src" -maxdepth 1 -type f -iname install.wim | head -n 1)
601-
[ ! -f "$wim" ] && wim=$(find "$src" -maxdepth 1 -type f -iname install.esd | head -n 1)
600+
wim=$(find "$src" -maxdepth 1 -type f -iname install.wim -print -quit)
601+
[ ! -f "$wim" ] && wim=$(find "$src" -maxdepth 1 -type f -iname install.esd -print -quit)
602602

603603
if [ ! -f "$wim" ]; then
604604
warn "failed to locate 'install.wim' or 'install.esd' in ISO image, $FB" && return 1
@@ -892,14 +892,14 @@ updateImage() {
892892
rm -rf "$tmp"
893893
mkdir -p "$tmp"
894894

895-
src=$(find "$dir" -maxdepth 1 -type d -iname sources | head -n 1)
895+
src=$(find "$dir" -maxdepth 1 -type d -iname sources -print -quit)
896896

897897
if [ ! -d "$src" ]; then
898898
error "failed to locate 'sources' folder in ISO image, $FB" && return 1
899899
fi
900900

901-
wim=$(find "$src" -maxdepth 1 -type f -iname boot.wim | head -n 1)
902-
[ ! -f "$wim" ] && wim=$(find "$src" -maxdepth 1 -type f -iname boot.esd | head -n 1)
901+
wim=$(find "$src" -maxdepth 1 -type f -iname boot.wim -print -quit)
902+
[ ! -f "$wim" ] && wim=$(find "$src" -maxdepth 1 -type f -iname boot.esd -print -quit)
903903

904904
if [ ! -f "$wim" ]; then
905905
error "failed to locate 'boot.wim' or 'boot.esd' in ISO image, $FB" && return 1
@@ -962,7 +962,7 @@ updateImage() {
962962

963963
local find="$file"
964964
[[ "$MANUAL" == [Yy1]* ]] && find="$org"
965-
path=$(find "$dir" -maxdepth 1 -type f -iname "$find" | head -n 1)
965+
path=$(find "$dir" -maxdepth 1 -type f -iname "$find" -print -quit)
966966

967967
if [ -f "$path" ]; then
968968
if [[ "$MANUAL" != [Yy1]* ]]; then

0 commit comments

Comments
 (0)