Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Verify files are not empty #463

Merged
merged 5 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/boot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@ if [[ "${BOOT_MODE,,}" != "legacy" ]] && [[ "${BOOT_MODE,,}" != "windows_legacy"
OVMF="/usr/share/OVMF"
DEST="$STORAGE/${BOOT_MODE,,}"

if [ ! -f "$DEST.rom" ]; then
[ ! -f "$OVMF/$ROM" ] && error "UEFI boot file ($OVMF/$ROM) not found!" && exit 44
if [ ! -s "$DEST.rom" ]; then
[ ! -s "$OVMF/$ROM" ] && error "UEFI boot file ($OVMF/$ROM) not found!" && exit 44
cp "$OVMF/$ROM" "$DEST.rom"
fi

if [ ! -f "$DEST.vars" ]; then
[ ! -f "$OVMF/$VARS" ] && error "UEFI vars file ($OVMF/$VARS) not found!" && exit 45
if [ ! -s "$DEST.vars" ]; then
[ ! -s "$OVMF/$VARS" ] && error "UEFI vars file ($OVMF/$VARS) not found!" && exit 45
cp "$OVMF/$VARS" "$DEST.vars"
fi

Expand Down
6 changes: 3 additions & 3 deletions src/disk.sh
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ addDisk () {
FS=$(stat -f -c %T "$DIR")
checkFS "$FS" "$DISK_FILE" "$DISK_DESC" || exit $?

if ! [ -f "$DISK_FILE" ] ; then
if ! [ -s "$DISK_FILE" ] ; then

if [[ "${DISK_FMT,,}" != "raw" ]]; then
PREV_FMT="raw"
Expand All @@ -408,12 +408,12 @@ addDisk () {
fi
PREV_EXT=$(fmt2ext "$PREV_FMT")

if [ -f "$DISK_BASE.$PREV_EXT" ] ; then
if [ -s "$DISK_BASE.$PREV_EXT" ] ; then
convertDisk "$DISK_BASE.$PREV_EXT" "$PREV_FMT" "$DISK_FILE" "$DISK_FMT" "$DISK_BASE" "$DISK_DESC" "$FS" || exit $?
fi
fi

if [ -f "$DISK_FILE" ]; then
if [ -s "$DISK_FILE" ]; then

CUR_SIZE=$(getSize "$DISK_FILE")

Expand Down
2 changes: 1 addition & 1 deletion src/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ info "$MSG" && html "$MSG"
fKill "progress.sh"

(( rc != 0 )) && error "Failed to download $BOOT , reason: $rc" && exit 60
[ ! -f "$TMP" ] && error "Failed to download $BOOT" && exit 61
[ ! -s "$TMP" ] && error "Failed to download $BOOT" && exit 61

html "Download finished successfully..."

Expand Down
4 changes: 2 additions & 2 deletions src/network.sh
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ closeNetwork() {
else

local pid="/var/run/dnsmasq.pid"
[ -f "$pid" ] && pKill "$(<"$pid")"
[ -s "$pid" ] && pKill "$(<"$pid")"

ip link set "$VM_NET_TAP" down promisc off || true
ip link delete "$VM_NET_TAP" || true
Expand Down Expand Up @@ -251,7 +251,7 @@ getInfo() {

if [ -z "$MAC" ]; then
local file="$STORAGE/$PROCESS.mac"
[ -f "$file" ] && MAC=$(<"$file")
[ -s "$file" ] && MAC=$(<"$file")
if [ -z "$MAC" ]; then
# Generate MAC address based on Docker container ID in hostname
MAC=$(echo "$HOST" | md5sum | sed 's/^\(..\)\(..\)\(..\)\(..\)\(..\).*$/02:\1:\2:\3:\4:\5/')
Expand Down
2 changes: 1 addition & 1 deletion src/progress.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fi

while true
do
if [ -f "$file" ]; then
if [ -s "$file" ]; then
bytes=$(du -sb "$file" | cut -f1)
if (( bytes > 1000 )); then
size=$(echo "$bytes" | numfmt --to=iec --suffix=B | sed -r 's/([A-Z])/ \1/')
Expand Down
Loading