Skip to content

Commit b9971cf

Browse files
committedFeb 10, 2025·
Always remove fsck recovered files on boot
A recent change made the image cleanup conditional on successful archiving, which had the unwanted side effect of no longer removing files recovered by fsck when TeslaUSB boots, which apparently confuse the car. Make it so that those file are removed again when TeslaUSB boots.
1 parent b6b5d52 commit b9971cf

File tree

1 file changed

+35
-25
lines changed

1 file changed

+35
-25
lines changed
 

‎run/archiveloop

+35-25
Original file line numberDiff line numberDiff line change
@@ -356,17 +356,22 @@ function intersect {
356356

357357
function clean_cam_mount {
358358

359-
if [ -e /tmp/last_clean_time ]
359+
local mode="${1:-}"
360+
361+
if [ "$mode" = "freespace" ]
360362
then
361-
read -r -d . last < /tmp/last_clean_time
362-
read -r -d . now < /proc/uptime
363-
if (( (now - last) < 300 ))
363+
if [ -e /tmp/last_clean_time ]
364364
then
365-
log "skipping cleaning cam mount"
366-
return
365+
read -r -d . last < /tmp/last_clean_time
366+
read -r -d . now < /proc/uptime
367+
if (( (now - last) < 300 ))
368+
then
369+
log "skipping cleaning cam mount"
370+
return
371+
fi
367372
fi
373+
cat /proc/uptime > /tmp/last_clean_time
368374
fi
369-
cat /proc/uptime > /tmp/last_clean_time
370375

371376
log "cleaning cam mount"
372377
ensure_cam_file_is_mounted
@@ -378,26 +383,29 @@ function clean_cam_mount {
378383
# Delete short recordings
379384
(cd "${CAM_MOUNT}"; find . -type f -name \*.mp4 -size -100000c -printf '%P\n' ) | xargs rm -rf
380385

381-
# Remove files, oldest first, until there is at least 20GB of free space
382-
383-
(cd "${CAM_MOUNT}"; find . -type f -a \( -path './TeslaCam/*' -o -path './TeslaTrackMode/*' \) -printf '%P\0') > /tmp/rmcandidates.txt
384-
if [ -s /tmp/rmcandidates.txt ]
386+
if [ "$mode" = "freespace" ]
385387
then
386-
(cd "${CAM_MOUNT}"; xargs -a /tmp/rmcandidates.txt -0 ls -cr1) > /tmp/rmcandidatesbytime.txt
387-
else
388-
true > /tmp/rmcandidatesbytime.txt
389-
fi
390-
391-
local freespace
392-
while read -r line
393-
do
394-
freespace=$(eval "$(stat --file-system --format="echo \$((%f*%S))" "${CAM_MOUNT}/.")")
395-
if ((freespace > 20000000000))
388+
# Remove files, oldest first, until there is at least 20GB of free space
389+
390+
(cd "${CAM_MOUNT}"; find . -type f -a \( -path './TeslaCam/*' -o -path './TeslaTrackMode/*' \) -printf '%P\0') > /tmp/rmcandidates.txt
391+
if [ -s /tmp/rmcandidates.txt ]
396392
then
397-
break;
393+
(cd "${CAM_MOUNT}"; xargs -a /tmp/rmcandidates.txt -0 ls -cr1) > /tmp/rmcandidatesbytime.txt
394+
else
395+
true > /tmp/rmcandidatesbytime.txt
398396
fi
399-
rm "${CAM_MOUNT}/$line"
400-
done < /tmp/rmcandidatesbytime.txt
397+
398+
local freespace
399+
while read -r line
400+
do
401+
freespace=$(eval "$(stat --file-system --format="echo \$((%f*%S))" "${CAM_MOUNT}/.")")
402+
if ((freespace > 20000000000))
403+
then
404+
break;
405+
fi
406+
rm "${CAM_MOUNT}/$line"
407+
done < /tmp/rmcandidatesbytime.txt
408+
fi
401409

402410
# delete directories that are now empty
403411
find "$CAM_MOUNT/TeslaCam/RecentClips" "$CAM_MOUNT/TeslaCam/SavedClips" \
@@ -634,7 +642,7 @@ function archive_teslacam_clips () {
634642
then
635643
if [ "$archive_success" = "true" ]
636644
then
637-
clean_cam_mount
645+
clean_cam_mount freespace
638646
else
639647
log "Skipping cleaning step after archive error"
640648
fi
@@ -852,6 +860,8 @@ logrotator &
852860
wifichecker &
853861

854862
fix_errors_in_images
863+
# always remove files that fsck recoverd
864+
clean_cam_mount boot
855865

856866
if has_cam_disk
857867
then

0 commit comments

Comments
 (0)
Please sign in to comment.