I wrote a little script I use to implement the deletion of empty sub directories in my templates (execute as root):
cat <<EOF > /root/delete_empty_incoming.sh
#!/bin/sh
test ! -d /home/user/QubesIncoming || find '/home/user/QubesIncoming/' -mindepth 1 -type d -exec rmdir '{}' \;
EOF
chmod +x /root/delete_empty_incoming.sh
cat <<EOF > /etc/systemd/system/delete_empty_incoming.service
[Unit]
Description=Empty QubesIncoming
[Service]
ExecStart=/root/delete_empty_incoming.sh
[Install]
WantedBy=multi-user.target
EOF
systemctl enable delete_empty_incoming
systemctl start delete_empty_incoming
systemctl status delete_empty_incoming
3 Likes
solene
December 27, 2024, 7:14pm
42
good idea to use systemd here, you could improve it using systemd to check the condition and run the command instead of using a shell script. This will make deployment easier.
https://www.freedesktop.org/software/systemd/man/latest/systemd.path.html#PathExists=
2 Likes
Mi-ch
March 11, 2025, 8:07pm
43
Note that there is an --ignore-fail-on-non-empty
option that makes rmdir
silently ignore any non empty folder.
In my own case, since I only want to remove empty top-level folders, I simply use:
rmdir /home/user/QubesIncoming/* --ignore-fail-on-non-empty
3 Likes
This will be an option in 4.3
opened 01:55AM - 01 Jul 23 UTC
closed 11:03PM - 19 Oct 24 UTC
C: core
P: minor
release notes
ux
pr submitted
affects-4.3
[How to file a helpful issue](https://www.qubes-os.org/doc/issue-tracking/)
#… ## The problem you're addressing (if any)
After copying or moving a file from one qube to another, a `QubesIncoming` directory is created along with suitable subdirectories. Usually, the user moves the file out of this directory structure in order to make use of the file. This often leaves behind an empty `QubesIncoming` directory (often with empty subdirectories). These persist until the user manually cleans them up.
### The solution you'd like
Automatically remove the empty `QubesIncoming` directory whenever the qube starts up or shuts down (not sure which is better). For present purposes:
- A `QubesIncoming` directory that contains only empty subdirectories still counts as empty.
- A `QubesIncoming` directory that contains non-default hidden files does not count as empty.
### The value to a user, and who that user might be
Less clutter. Less time and effort spent manually cleaning up after the system.
4 Likes