Skip to content
Merged
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
46 changes: 20 additions & 26 deletions RaspberryPi/raspi-f2fs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -108,37 +108,31 @@ remove_ext4_configs() {
# Remove ext4-specific cron jobs
local cron_dir="$WD/t/r/etc/cron.d"
if [[ -d $cron_dir ]]; then
local -a cron_files=("$cron_dir"/*)
local -a cron_matches=()
if ((${#cron_files[@]})); then
while IFS= read -r -d '' f; do
cron_matches+=("$f")
done < <(grep -liZ -E 'e2fsck|tune2fs|ext4' "${cron_files[@]}" 2>/dev/null || true)

for f in "${cron_matches[@]}"; do
log "Removed ext4-specific cron job: ${f##*/}"
rm -f "$f"
done
fi
local files=()
while IFS= read -r -d '' f; do
files+=("$f")
done < <(grep -liZ "e2fsck\|tune2fs\|ext4" "$cron_dir"/* 2>/dev/null)
Comment on lines +112 to +114
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

While using a while read loop is a robust way to handle filenames, you can make this more concise and efficient by using mapfile (an alias for readarray). This aligns with the repository's style guide which prefers mapfile for populating arrays.

Suggested change
while IFS= read -r -d '' f; do
files+=("$f")
done < <(grep -liZ "e2fsck\|tune2fs\|ext4" "$cron_dir"/* 2>/dev/null)
mapfile -d '' -t files < <(grep -liZ "e2fsck\|tune2fs\|ext4" "$cron_dir"/* 2>/dev/null)
References
  1. The style guide recommends using mapfile -t for populating arrays. (link)

Comment on lines +111 to +114

for f in "${files[@]}"; do
log "Removed ext4-specific cron job: ${f##*/}"
rm -f "$f"
done
fi

# Remove ext4-specific systemd timers
local systemd_dir="$WD/t/r/etc/systemd/system"
if [[ -d $systemd_dir ]]; then
local -a timer_files=("$systemd_dir"/*.timer)
local -a timer_matches=()
if ((${#timer_files[@]})); then
while IFS= read -r -d '' f; do
timer_matches+=("$f")
done < <(grep -liZ -E 'e2fsck|tune2fs|ext4' "${timer_files[@]}" 2>/dev/null || true)

for f in "${timer_matches[@]}"; do
log "Removed ext4-specific systemd timer: ${f##*/}"
rm -f "$f"
# Remove corresponding service file
rm -f "${f%.timer}.service" 2>/dev/null || :
done
fi
local files=()
while IFS= read -r -d '' f; do
files+=("$f")
done < <(grep -liZ "e2fsck\|tune2fs\|ext4" "$systemd_dir"/*.timer 2>/dev/null)
Comment on lines +126 to +128
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to the previous block, you can use mapfile here for a more concise and performant way to populate the files array, adhering to the repository's style guide.

Suggested change
while IFS= read -r -d '' f; do
files+=("$f")
done < <(grep -liZ "e2fsck\|tune2fs\|ext4" "$systemd_dir"/*.timer 2>/dev/null)
mapfile -d '' -t files < <(grep -liZ "e2fsck\|tune2fs\|ext4" "$systemd_dir"/*.timer 2>/dev/null)
References
  1. The style guide recommends using mapfile -t for populating arrays. (link)

Comment on lines +126 to +128

for f in "${files[@]}"; do
log "Removed ext4-specific systemd timer: ${f##*/}"
rm -f "$f"
# Remove corresponding service file
rm -f "${f%.timer}.service" 2>/dev/null || :
done
fi

log "ext4-specific configs removed"
Expand Down
Loading