Skip to content

move: add --leave-root to control --delete-empty-src-dirs behavior - fixes #7478 - #7618

Open
nielash wants to merge 1 commit into
rclone:masterfrom
nielash:move-leave-root
Open

nielash wants to merge 1 commit into
rclone:masterfrom
nielash:move-leave-root

Conversation

@nielash

@nielash nielash commented Feb 6, 2024 •

Copy link
Copy Markdown
Contributor

What is the purpose of this change?

Before this change, it was not always possible to delete an empty source root directory during rclone move. Furthermore, the behavior was inconsistent based on whether the move was performed server-side or via the fallback to copy + delete.

After this change, a --leave-root flag is added to control whether --delete-empty-src- dirs deletes an empty src root. (It has no effect if --delete-empty-src-dirs=false or if the src root isn't empty.)

Note that --leave-root defaults to false, which is arguably a breaking change, although also arguably not, since the prior behavior was already inconsistent (the root was, in fact, still deleted for server-side moves without filters.) Defaulting to false also makes it consistent with the identical option in rclone rmdirs.

This setting should be particularly helpful for users wanting to rename a directory in place.

Note that both --delete-empty-src-dirs and --leave-root are effectively ignored for server-side directory move operations without filters, which always use the equivalent of --delete-empty-src-dirs=true --leave-root=false. (This is not a change, but was not previously documented.)

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

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 :-)

…ixes rclone#7478

Before this change, it was not always possible to delete an empty source root
directory during `rclone move`. Furthermore, the behavior was inconsistent based
on whether the move was performed server-side or via the fallback to copy +
delete.

After this change, a --leave-root flag is added to control whether --delete-empty-src-
dirs deletes an empty src root. (It has no effect if --delete-empty-src-dirs=false or
if the src root isn't empty.)

Note that --leave-root defaults to false, which is arguably a breaking change,
although also arguably not, since the prior behavior was already inconsistent
(the root was, in fact, still deleted for server-side moves without filters.)
Defaulting to false also makes it consistent with the identical option in
`rclone rmdirs`.

This setting should be particularly helpful for users wanting to rename a
directory in place.

Note that both --delete-empty-src-dirs and --leave-root are effectively ignored for
server-side directory move operations without filters, which always use the
equivalent of --delete-empty-src-dirs=true --leave-root=false. (This is not a change,
but was not previously documented.)
@nielash
nielash marked this pull request as ready for review February 6, 2024 18:12

@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.

I missed reviewing this before - sorry!

I think changing the defaults is not without risk - there is just bound to be a user or two relying on the fact that --delete-empty-src-dirs doesn't delete the root sometimes.

However I agree that this is very inconsistent and makes the rename case impossible, so arguably a bug.

The --leave-root flag should probably be on the rclone move command directly like --delete-empty-src-dirs is rather being a global though.

What do you think?

Do you want to get this into 1.68?

@nielash

nielash commented Aug 23, 2024

Copy link
Copy Markdown
Contributor Author

The --leave-root flag should probably be on the rclone move command directly like --delete-empty-src-dirs is rather being a global though.

I think --delete-empty-src-dirs is only able to pull that off because the moveDir functions take a dedicated deleteEmptySrcDirs parameter... are you suggesting that we change the function signatures to add another one? That seems like the more invasive change to me...

@ncw

ncw commented Aug 23, 2024

Copy link
Copy Markdown
Member

The --leave-root flag should probably be on the rclone move command directly like --delete-empty-src-dirs is rather being a global though.

I think --delete-empty-src-dirs is only able to pull that off because the moveDir functions take a dedicated deleteEmptySrcDirs parameter... are you suggesting that we change the function signatures to add another one? That seems like the more invasive change to me...

Yes that will be more invasive, certainly.

I don't think we want a --leave-root flag on the main binary which is only useful for move though (I know there lots already but I've been trying not to add more!)

We could change the function to take a moveOpts struct instead which is nice to use on the RC. And is the way the check functions work.

Or if we do want to make a global then it needs a more precise name like --leave-root-on-move but I'm not keen on that.

I haven't looked through the consequences of changing the move functions yet though so there may be more to it.

It might be that a bigger reorg should be done with sync copy and move.

Thoughts?

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.

--delete-empty-src-dirs improvement on rclone move (--leave-root=false)

2 participants