[PATCH v2 4/7] host/rootfs: clean up obsolete tmp dirs on mount

Alyssa Ross
2025-12-14T01:47:53Z

In the ideal case, these will be cleaned up when the VM running them
exits, but there's always the possibility that there are some left
over, in which case mount time is the perfect time to clean up, when
we can be reasonably sure nothing else is still accessing them.

Signed-off-by: Alyssa Ross <hi@alyssa.is>
---
v2: no change, but thanks to rebase no longer fails to exit after
outputting error message as identified last time.
v1: https://spectrum-os.org/lists/archives/spectrum-devel/20251213161637.510752-4-hi@alyssa.is/

host/rootfs/image/usr/bin/mount-userdata | 42 ++++++++++++++++--------
1 file changed, 28 insertions(+), 14 deletions(-)

diff --git a/host/rootfs/image/usr/bin/mount-userdata b/host/rootfs/image/usr/bin/mount-userdata
index 71f12c55..4b9dc8a1 100755
--- a/host/rootfs/image/usr/bin/mount-userdata
+++ b/host/rootfs/image/usr/bin/mount-userdata
@@ -7,21 +7,35 @@ backtick -D "" uuid {
blkid -o value -s UUID -- $1
}

-multisubstitute {
- importas -Siu 0
- importas -Siu 1
- importas -Siu uuid
-}
-
-case $uuid {
- "" {
- if {
- fdmove -c 1 2
- printf "%s: '%s' does not have a UUID\n" $0 $1
- }
- exit 1
+if {
+ multisubstitute {
+ importas -Siu 0
+ importas -Siu 1
+ importas -Siu uuid
}
+
+ case $uuid {
+ "" {
+ if {
+ fdmove -c 1 2
+ printf "%s: '%s' does not have a UUID\n" $0 $1
+ }
+ exit 1
+ }
+ }
+
+ mount -m -t btrfs -o nosuid,nodev,noexec,nosymfollow -- $1 /media/${uuid}
+}
+
+importas -Siu uuid
+
+foreground {
+ if -t { test -d /media/${uuid}/Spectrum/data/spectrum/storage }
+ find /media/${uuid}/Spectrum/data/spectrum/storage
+ -mindepth 1
+ -maxdepth 1
+ -name tmp.*
+ -exec rm -rf -- {} ;
}

-if { mount -m -t btrfs -o nosuid,nodev,noexec,nosymfollow -- $1 /media/${uuid} }
printf "%s\n" /media/${uuid}
--
2.51.0