Deleting files from specific folders upon exit of non-disposable qube

I’d like to have all files from specific folders deleted from a non-disposable qube, under certain circumstances -

Ideally - When all windows of a qube are closed
Can live with - When the qube is restarted

It seems like the standard practice is to use named disposables. I’m finding this cumbersome to configure and in some cases I may want files in certain folders to persist across qube restarts.

My primary use case is to delete files from the $HOME/Downloads and $HOME/QubesIncoming folders.

I’ve imagined an inelegant solution that uses cron but feel the timing might not be great. So I’m wondering if there might be a way to trigger the delete process when all windows of a qube are closed or at least when the qube is restarted.

I mount them as tmpfs using /rw/config/rc.local.

3 Likes

Custom persist feature

There is already a mechanism to clean up empty directories in
QubesIncoming - you could leverage this by editing the service in
/usr/lib/qubes/init/misc-post-stop.sh

But then you will have to watch for any updates that affect that
service.
Better would be to use a simple service that runs using
ExecStop. You could either put this in the template and
enable it where needed, or implement it in the qube and enable the
service there.

Something like:delete_dirs.sh

#!/bin/sh
rm -rf /home/user/Downloads
rm -rf /home/user/QubesIncoming

With a service file like this:

[Unit]
Description=Run delete_dirs before shutdown
After=network.target

[Service]
Type=oneshot
ExecStop=/usr/bin/delete_dirs.sh
RemainAfterExit=yes

[Install]
WantedBy=multi-user.target
I never presume to speak for the Qubes team. When I comment in the Forum I speak for myself.
1 Like