rclonesync-V2 icon indicating copy to clipboard operation
rclonesync-V2 copied to clipboard

rclonesync does not sync empty directories

Open tliero opened this issue 4 years ago • 7 comments

When syncing a local directory with a (Google Drive) remote, empty directories that exist either on Path1 or Path2 are not being created on the other. While for "end user files" this behavior might be acceptable, especially folder structures that belong to programs might expect empty directories to be in place.

Edit: Adding --rclone-args --create-empty-src-dirs as last parameter unfortunately does not solve the issue, as --create-empty-src-dirs is not a global rclone parameter. This results in rclone lsl returning an error.

tliero avatar Sep 21 '20 13:09 tliero

Edit: Adding --rclone-args --create-empty-src-dirs as last parameter unfortunately does not solve the issue, as --create-empty-src-dirs is not a global rclone parameter. This results in rclone lsl returning an error.

That's unfortunate. I wonder if any --rclone-args can be discarded for the rclone LSLs.

cjnaz avatar Sep 22 '20 20:09 cjnaz

I guess global flags would still be expected to be passed on to all subcommands. Subcommand-specific flags like --create-empty-src-dirs seem to be the rare exception for rclone. So either rclonesync would have to recognize specific flags or there needs to be a way to pass on flags to sub-commands only, e.g. --rclone-copy-args. But that would create a problem with the catch-all structure of the command line and make it impossible to pass global and specific args at the same time. Maybe it would actually be the easiest to just recognize the few subcommand-specific args.

tliero avatar Sep 23 '20 10:09 tliero

The problem is rooted in rclonesync specifically and only working on files. File differences are found and propagated to the other side. A parallel algorithm would have to be implemented to check for directory differences (specifically empty directory adds and deletes) and propagate those to the other side.

A not-very-robust workaround is to do a an rclone sync from your master path to the other with --create-empty-src-dirs. A --filter "- *" with --create-empty-src-dirs may cause rclone to touch only empty directories, and thus not force the need for an rclonesync --first-sync to follow. Any deleted empty directories would have to be manually deleted on the other side as directories themselves are not tracked.

I'll leave this open for the record. Its a limitation.

cjnaz avatar Sep 24 '20 16:09 cjnaz

This sequence may get you close to what you need

1) rclonesync <path1> <path2>
2) rclone copy <path1> <path2> --filter "+ */" --filter "- **" --create-empty-src-dirs
3) rclone copy <path2> <path1> --filter "+ */" --filter "- **" --create-empty-src-dirs

The filtering in line 2 first includes all directories in path1, and then excludes everything else in path1. The empty directories in path1 are created on path2. The filtering on line 3 does the same for path2 to path1.

The limitation is that empty directories only accumulate, and must be manually deleted on both sides. You could use rlconesync's --remove-empty-directories switch to clean them out of both paths, or rclone's rmdirs command.

cjnaz avatar Sep 25 '20 17:09 cjnaz

Is there any way to automatically delete empty directories on the remote that aren't present on local storage? I ended up with a ton of them and I think I'm getting throttled when doing rclone lsl on the remote because it takes more than an hour.

Update: I managed to delete them using the web interface of the cloud service, sorting by content size. It would still be nice if the program could delete empty directories on one path when they're deleted on the other.

bloatmode avatar Mar 14 '22 16:03 bloatmode

Did you try the --remove-empty-directories switch?

cjnaz avatar Mar 15 '22 03:03 cjnaz

Thanks! Sorry for bumping this issue, I found it before reading the documentation when searching for my problem.

bloatmode avatar Mar 15 '22 15:03 bloatmode