Skip to content

operations: --no-block-rmdir for disposable files blocking removal of otherwise empty directory - #7512

Open
nielash wants to merge 1 commit into
rclone:masterfrom
nielash:no-block-rmdir
Open

nielash wants to merge 1 commit into
rclone:masterfrom
nielash:no-block-rmdir

Conversation

@nielash

@nielash nielash commented Dec 18, 2023 •

Copy link
Copy Markdown
Contributor

What is the purpose of this change?

Before this change, rclone commands that remove empty dirs (including rmdir, rmdirs, sync, and bisync) would silently fail to remove dirs if those dirs contained files that were excluded by filters. This can pose a problem for some automatically created system files, such as .DS_Store on macOS, which users often prefer to exclude from syncs -- including them makes for noisy logs, but excluding them can make it impossible to remove otherwise empty directories.

After this change, a new --no-block-rmdir flag allows specifying a comma-separated list of such files which rclone should consider "disposable" if they block removal of otherwise empty directories. When set, if rclone fails to remove a directory, it will check the contents of the directory (ignoring any filters.) If the directory contains ONLY files on the disposable list, rclone will delete the files and then remove the directory.

Was the change discussed in an issue or in the forum before?

See partially-related #6437

Checklist

  • I have read the contribution guidelines.
  • I have added tests for all changes in this PR if appropriate.
  • I have added documentation for the changes if appropriate.
  • All commit messages are in house style.
  • I'm done, this Pull Request is ready for review :-)

@nielash

nielash commented Mar 27, 2024

Copy link
Copy Markdown
Contributor Author

Rebased and resolved merge conflicts.

@ncw ncw left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code looks neat and well implemented :-)

My immediate thoughts are

  • Are users going to want to use a glob, eg --no-block-rmdir *~ for all the emacs users in the world - I think probably not but we should discuss now.
  • Can we think of a better name than -no-block-rmdir?
  • How useful is this in the mac world? Can you describe use cases that this fixes?

@nielash

nielash commented Apr 3, 2024

Copy link
Copy Markdown
Contributor Author
  • Are users going to want to use a glob, eg --no-block-rmdir *~ for all the emacs users in the world - I think probably not but we should discuss now.

Possibly! I think that would be a useful feature, at the possible cost of adding some complexity.

  • Can we think of a better name than -no-block-rmdir?

Haha. Some ideas:

  • --ignorable
  • --deletable
  • --removable
  • --disposable
  • --discardable

Syncthing has a similar feature but it doesn't seem to have a name.

  • How useful is this in the mac world? Can you describe use cases that this fixes?

Pretty useful, IMO. The main use case is for .DS_Store files, since the OS creates them in every folder whether you like it or not. Here are two examples:

  • You have a crypt remote that is wrapping local. If you do nothing, the OS will create .DS_Store files which crypt will complain about (mixing crypt and non-crypt in the same dir). But if you exclude the .DS_Store files with filters, you'll never be able to delete directories through crypt.
  • You are bisyncing local with drive on a regular basis. If you do nothing, your drive activity history will always be filled with noisy activity logs showing changes in folders which shouldn't have changed -- which could be especially confusing for any other users you're sharing the folder with. But if you exclude the .DS_Store files with filters, deleting a directory on drive will cause bisync to fail when it tries to delete the corresponding directory on local.

Note also that .DS_Store files are strictly forbidden on dropbox, so dropbox users really have no choice but to filter these out and deal with possibly undeleteable directories when syncing dropbox to local.

Here's another example where this came up recently on the forum:

@edc-w edc-w removed the new feature label Jun 17, 2024
… otherwise empty directory

Before this change, rclone commands that remove empty dirs (including rmdir,
rmdirs, sync, and bisync) would silently fail to remove dirs if those dirs
contained files that were excluded by filters. This can pose a problem for some
automatically created system files, such as `.DS_Store` on macOS, which users
often prefer to exclude from syncs -- including them makes for noisy logs, but
excluding them can make it impossible to remove otherwise empty directories.

After this change, a new `--no-block-rmdir` flag allows specifying a
comma-separated list of such files which rclone should consider "disposable" if
they block removal of otherwise empty directories. When set, if rclone fails to
remove a directory, it will check the contents of the directory (ignoring any
filters.) If the directory contains ONLY files on the disposable list, rclone
will delete the files and then remove the directory.

See also: partially-related rclone#6437
@ncw

ncw commented Sep 27, 2024

Copy link
Copy Markdown
Member

I just had a thought... We have a flag which almost does this already for sync that is --delete-excluded

I don't know whether this flag works for bisync but maybe it should?

What do you think?

@nielash

nielash commented Sep 27, 2024

Copy link
Copy Markdown
Contributor Author

I just had a thought... We have a flag which almost does this already for sync that is --delete-excluded

I think that is different, as here we don't want to delete ALL excluded files -- only the ones with a certain name.

It is common to use filters to sync only a subset of folders within a drive (but the excluded folders should not get deleted.)

@ncw

ncw commented Sep 30, 2024

Copy link
Copy Markdown
Member

I just had a thought... We have a flag which almost does this already for sync that is --delete-excluded

I think that is different, as here we don't want to delete ALL excluded files -- only the ones with a certain name.

It is common to use filters to sync only a subset of folders within a drive (but the excluded folders should not get deleted.)

If you put all the directories that you wanted excluding into filters then --delete-excluded is exactly the same as --no-block-rmdir.

I'm not fond of the UI for --no-block-rmdir it seems a bit ad-hoc. At minimum we should make the parameters globs I think.

On the other hand the implementation is very simple and contained which is a big plus.

Do you think users will always have the directories in --no-block-rmdir excluded by filters? I wonder if we can combine that with the filtering somehow? Maybe --exclude-and-delete glob which could act exactly like --exclude but also fill in an internal "no block rmdir" list, (which could be extended to files too?).

What do you think about a name --delete-excluded-dirs glob instead of --no-block-rmdir?

Sorry, not quite happy with this yet for reasons I'm finding hard to pin down!

PS We can use slices now as our minimum is go1.21 :-)

@nielash

nielash commented Sep 30, 2024

Copy link
Copy Markdown
Contributor Author

If you put all the directories that you wanted excluding into filters then --delete-excluded is exactly the same as --no-block-rmdir.

I think I am still not understanding this point. How is it exactly the same?

With --delete-excluded, how do I distinguish between the excluded files that should be deleted and the excluded files which should NOT be deleted?

What do you think about a name --delete-excluded-dirs glob instead of --no-block-rmdir?

I don't quite understand the "dirs" part, as we are talking about deleting files here, not dirs. (Yes it is for the broader purpose of not blocking removal of its parent dir, if that dir would be getting removed anyway for some other reason. But it is only the file that is excluded with filters -- not the dir. In fact, this feature is only concerned with dirs which are NOT themselves excluded.)

Note also that the goal here is not to rmdirs all empty directories. Rather, the goal is to allow individual directories on the dst to be removed when (and only when) the corresponding src directory has been removed, and when the only thing blocking that removal is the presence of an excluded system file with a particular name.

Sorry, not quite happy with this yet for reasons I'm finding hard to pin down!

I wonder if it would be helpful to take inspiration from Syncthing's similar feature? (Search that page for (?d))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants