Github Issue #8307 - Automatically clean up `QubesIncoming` directory if empty

Github Issue #8307 - Automatically clean up QubesIncoming directory if empty

on Jul 1, 2023 adw writes:

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.

And suggests

Automatically remove the empty QubesIncoming directory whenever the qube starts up or shuts down (not sure which is better). For present purposes:

Diagnosis and Analysis

None

Solution

This is extremely easy to fix. The "find(1)" command could find and delete empty files and empty directories. It is only necessary to add the proper ‘find’ command to a post-startup or pre-shutdown script. I personally prefer a pre-shutdown script (if available).

I will wait for one week to see if anyone else is willing to send the PR, then will act myself.

2 Likes

Proper find command can be found in this topic:

2 Likes

Here:

I think this line is redundant:

    find /home/user/QubesIncoming -type f -empty -delete

Deleting the empty (zero-bytes) files might not be necessary but does not harm. A scenario where empty files were left in the QubesIncoming folder could be envisioned.

On second thought this command:

    find /home/user/QubesIncoming -type d -empty -delete

Will remove all the empty directories inside all subdirectories which could be unwanted.
I guess it’s better to add -maxdepth 1 so it’ll only remove the empty directories in /home/user/QubesIncoming:

    find /home/user/QubesIncoming -maxdepth 1 -type d -empty -delete

Or search all the subdirectories and remove the parent directory only if there are no files present.

I don’t think there is a need to remove the empty files.
The empty files are different from the empty directories. The empty directories left after user moved their content to the different directory are expected to be unneeded, but empty files would’ve been created by user with some purpose in mind and I don’t think it’s ok to remove them.

Doesn’t the -empty option do this exactly? Removing directories (and sub-directories) only if they contain no files?

No:

[workstation user ~]% mkdir 1                
[workstation user ~]% mkdir 1/1
[workstation user ~]% mkdir 1/2
[workstation user ~]% mkdir 1/1/1
[workstation user ~]% mkdir 1/1/2
[workstation user ~]% touch 1/1/1/a          
[workstation user ~]% tree 1       
1
├── 1
│   ├── 1
│   │   └── a
│   └── 2
└── 2

5 directories, 1 file
[workstation user ~]% find 1 -type d -empty 
1/1/2
1/2

@kenosen Maybe it would be better to keep the empty files as @apparatus suggests. I would suggest waiting for other opinions and act accordingly after having a majority consensus.

@adw Since you opened the original issue, what is your suggestion?

  1. Deleting the QubesIncoming on shutdown regardless of it’s content (I do not like this).
  2. Deleting the empty files and empty directories inside QubesIncoming recursively
  3. Deleting the only the empty directories at dept 1

cc. @solene Who has made suggestion about this before.

A is a regular file? If yes, that is what I expected (i.e. 1/1/2 & 1/2 to be deleted).
p.s. The reason I liked the idea of deleting empty (zero size) files was that it would actually delete 'A'

Yes, a is a regular file.
But in this case it’ll remove the empty directory that could be needed.

OK. I think It would be better to wait and see what would adw and solene (and others) would suggest. I am OK with both scenario 2 & 3 which I mentioned earlier.

E.g.:

[workstation user ~]% tree QubesIncoming                               
QubesIncoming
└── disp1234
    └── myappsrc
        ├── build
        ├── Makefile
        └── src
            └── myapp.c

5 directories, 2 files

Makefile could expect for the (empty) build directory to exist.

2 Likes

Makes sense

I personally need to keep QubesIncoming as it’s bookmarked in my file manager, the bookmark is removed if the directory disappear, it would be really annoying if it’s an opt-out feature.

@kenosen

Would you kindly amend your PR and add -mindepth 1 to it? Like this:

find /home/user/QubesIncoming -mindepth 1 -type d -empty -delete

can do!

In this case this is not removing QubesIncoming which may not be what people want (still an improvement, but that’s from my point of view).

I’m not sure we can make everyone happy by changing this though.

1 Like

Well. Marek has got veto power in the end and will decide on the final form

You can just make a dummy directory with a file, if you don’t want QubesIncoming to be deleted.

1 Like