Skip to content

Sync fails when a new file has the same name as an old directory #2231

Description

@anisse

What is the problem you are having with rclone?

When using the sync command, it doesn't delete (recursively) directories on the remote that have been replaced with a single file having the same name.

What is your rclone version (eg output from rclone -V)

rclone v1.40-DEV

  • os/arch: linux/arm
  • go version: go1.9.3

Which OS you are using and how many bits (eg Windows 7, 64 bit)

Linux, ARMv7 (32 bits)

Which cloud storage system are you using? (eg Google Drive)

Swift

The command you were trying to run (eg rclone copy /tmp remote:tmp)

rclone --config ./rclone.conf sync --log-file sync-delete-ignore-err.log --ignore-errors --backup-dir remote:deleted/ my-local-dir remote:/remote-dir

It even retries on error, but always fails with the same error.

I see that there is a FIXME in the code, but I didn't find an issue for this exact problem:
https://github.com/ncw/rclone/blob/80588a5a6bea6efaf37bdad4598c735f9975d221/fs/sync/sync.go#L724

Activity

  1. ncw commented on Apr 12, 2018

    @ncw
    Member

    NB note that using --delete-before is a workaround for this issue.

    Yes I missed out those corer cases when writing the sync routine ;-)

    $ mkdir src dst
    $ mkdir src/directory
    $ touch src/directory/file.txt
    $ touch dst/directory
    $ 
    $ rclone sync -vv src dst
    2018/04/12 15:13:55 DEBUG : rclone: Version "v1.40-071-g681edcdb-mega" starting with parameters ["rclone" "sync" "-vv" "src" "dst"]
    2018/04/12 15:13:55 DEBUG : Using config file from "/home/ncw/.rclone.conf"
    2018/04/12 15:13:55 INFO  : Local file system at /tmp/dst: Modify window is 1ns
    2018/04/12 15:13:55 ERROR : directory: can't overwrite file with directory
    2018/04/12 15:13:55 INFO  : Local file system at /tmp/dst: Waiting for checks to finish
    2018/04/12 15:13:55 INFO  : Local file system at /tmp/dst: Waiting for transfers to finish
    2018/04/12 15:13:55 ERROR : Local file system at /tmp/dst: not deleting files as there were IO errors
    2018/04/12 15:13:55 ERROR : Local file system at /tmp/dst: not deleting directories as there were IO errors
    2018/04/12 15:13:55 ERROR : Attempt 1/3 failed with 0 errors and: can't overwrite file with directory
    2018/04/12 15:13:55 ERROR : directory: can't overwrite file with directory
    2018/04/12 15:13:55 INFO  : Local file system at /tmp/dst: Waiting for checks to finish
    2018/04/12 15:13:55 INFO  : Local file system at /tmp/dst: Waiting for transfers to finish
    2018/04/12 15:13:55 ERROR : Local file system at /tmp/dst: not deleting files as there were IO errors
    2018/04/12 15:13:55 ERROR : Local file system at /tmp/dst: not deleting directories as there were IO errors
    2018/04/12 15:13:55 ERROR : Attempt 2/3 failed with 0 errors and: can't overwrite file with directory
    2018/04/12 15:13:55 ERROR : directory: can't overwrite file with directory
    2018/04/12 15:13:55 INFO  : Local file system at /tmp/dst: Waiting for checks to finish
    2018/04/12 15:13:55 INFO  : Local file system at /tmp/dst: Waiting for transfers to finish
    2018/04/12 15:13:55 ERROR : Local file system at /tmp/dst: not deleting files as there were IO errors
    2018/04/12 15:13:55 ERROR : Local file system at /tmp/dst: not deleting directories as there were IO errors
    2018/04/12 15:13:55 ERROR : Attempt 3/3 failed with 0 errors and: can't overwrite file with directory
    2018/04/12 15:13:55 Failed to sync: can't overwrite file with directory
    

    Wheras rsync just overwrites it, no messing...

    $ rsync -av src/ dst/
    sending incremental file list
    ./
    directory/
    directory/file.txt
    
    sent 162 bytes  received 46 bytes  416.00 bytes/sec
    total size is 0  speedup is 0.00
    $ tree dst
    dst
    └── directory
        └── file.txt
    

    So that is what rclone should do I think

    Interestingly rsync bombs out the other way round (which is your issue)

    $ rm -rf src dst
    $ mkdir src dst
    $ touch src/file
    $ mkdir dst/file
    $ touch dst/file/file.txt
    $ 
    $ 
    $ rclone -vv --retries 1 sync src dst
    2018/04/12 15:17:43 DEBUG : rclone: Version "v1.40-071-g681edcdb-mega" starting with parameters ["rclone" "-vv" "--retries" "1" "sync" "src" "dst"]
    2018/04/12 15:17:43 DEBUG : Using config file from "/home/ncw/.rclone.conf"
    2018/04/12 15:17:43 INFO  : Local file system at /tmp/dst: Modify window is 1ns
    2018/04/12 15:17:43 ERROR : file: can't overwrite directory with file
    2018/04/12 15:17:43 INFO  : Local file system at /tmp/dst: Waiting for checks to finish
    2018/04/12 15:17:43 INFO  : Local file system at /tmp/dst: Waiting for transfers to finish
    2018/04/12 15:17:43 ERROR : Local file system at /tmp/dst: not deleting files as there were IO errors
    2018/04/12 15:17:43 ERROR : Local file system at /tmp/dst: not deleting directories as there were IO errors
    2018/04/12 15:17:43 ERROR : Attempt 1/1 failed with 0 errors and: can't overwrite directory with file
    2018/04/12 15:17:43 Failed to sync: can't overwrite directory with file
    
    $ rsync -av src/ dst/
    sending incremental file list
    cannot delete non-empty directory: file
    could not make way for new regular file: file
    ./
    
    sent 72 bytes  received 109 bytes  362.00 bytes/sec
    total size is 0  speedup is 0.00
    rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1196) [sender=3.1.2]
    

    What do you think rclone should do?

    Deleting a whole directory tree is quite unfriendly! (rclone copy should probably refuse to) Is there a flag which makes rsync delete a directory tree in the destination?

  2. added this to the Known Problem milestone on Apr 12, 2018
  3. anisse commented on Apr 12, 2018

    @anisse
    ContributorAuthor

    I honestly don't know what would be the best behaviour. Maybe since rclone sync has --backup-dir, and if it can safely backup files and directories recursively, then the fully recursive 'deletion' isn't such a big issue.

  4. eikenb commented on Jun 15, 2018

    @eikenb

    I get this error from time to time and the solution is always to just delete the directory so that the next sync will work. IMO the behavior should be just that. I use this as a remote backup of my local backup and I want an exactly duplicate made. One could say I want a remote clone ;).

    My vote is to have it remove the directory and everything in it and put the new file in its place.

  5. billdenney commented on Aug 29, 2018

    @billdenney

    I just started encountering the same error mentioned above, and like @eikenb, I think that sync should fully synchronize.

    In my mind, other actions like copy should make different decisions. For a copy operations, I would not expect a directory to disappear if I try to put a file there. For a sync operation, I expect that the destination is identical to the source as much as possible and that I’m warned in every case that it is not (unless flags are given to suppress those warnings).

    If an optional flag is added to cover overwriting directories or not, I would prefer that the default with sync is to make the destination look identical, but the user could override such that they are not identical (and those differences are warned when encountered).

  6. billdenney commented on Sep 19, 2018

    @billdenney

    As I'm working through this on my backups, I thought of a possible intermediate solution until a permanent solution is decided upon: Could rclone indicate the command to delete the remote directories manually?

    The rationale for me is that following an ubuntu upgrade, I now get about 20 of these errors, and manually tracking down the correct command to delete them all is time-consuming. I think that it may be simpler for rclone to give a command to run in the error message so that I could simply delete the directories manually.

    (For clarity, my preference is that with sync, the remote should be identical to the source on completion, and directories should be removed and replaced with files if that is what happened at the source.)

  7. ncw commented on Sep 19, 2018

    @ncw
    Member

    @billdenney outputting the command to run is a good idea. I'd like to fix this too but I've been short of time so if anyone would like to have a go I'd be grateful :-)

  8. billdenney commented on Oct 27, 2018

    @billdenney

    I took a look to try to generate a PR, but I may need some pointers (this would be my first attempt at programming Go). The things that I found and thought of are:

    1. I think that the errors should be NoRetryError since the error will not change without user intervention. Is that as simple as changing these lines:
      https://github.com/ncw/rclone/blob/6390dec7dbca8bcbcf1cb0a0da7f22e42007c502/fs/sync/sync.go#L803
      to err := errors.NoRetryError(errors.New("can't overwrite directory with file"))
      and
      https://github.com/ncw/rclone/blob/6390dec7dbca8bcbcf1cb0a0da7f22e42007c502/fs/sync/sync.go#L819
      to err := errors.NoRetryError(errors.New("can't overwrite file with directory"))
    2. I think that the Rmdir function will need a recursive option to be able to prep the directory. That is a major change across all backends, and I don't see the right way to do it in general. (Or, maybe I misunderstand the use of purge, and purge is already a recursive delete function.)
  9. ncw commented on Oct 28, 2018

    @ncw
    Member
    1. I think that the errors should be NoRetryError since the error will not change without user intervention. Is that as simple as changing these lines:

    Yes that looks correct

    2. I think that the Rmdir function will need a recursive option to be able to prep the directory. That is a major change across all backends, and I don't see the right way to do it in general. (Or, maybe I misunderstand the use of purge, and purge is already a recursive delete function.)

    operations.Purge is the correct thing to use as a recursive delete directory. Though if --backup-dir is in use then it should probably move the directory into the backup dir which will complicate things!

  10. ivandeex commented on Nov 16, 2020

    @ivandeex
    Member

    This issue seeks for volunteers.

  11. ivandeex commented on Feb 9, 2021

    @ivandeex
    Member

    @anisse @billdenney This problem is reported against obsolete rclone version. Can you reproduce it with rclone 1.54?

  12. 2 remaining items

  13. ivandeex commented on Feb 9, 2021

    @ivandeex
    Member

    @billdenney Thank you
    Assigning as active bug report for fix.
    cc @ncw

  14. modified the milestones: Known Problem, v1.55 on Feb 9, 2021
  15. modified the milestones: v1.55, v1.56 on Apr 3, 2021
  16. modified the milestones: v1.56, v1.57 on Jul 20, 2021
  17. modified the milestones: v1.57, Known Problem on Nov 1, 2021
  18. ac615223s5 commented on Dec 20, 2024

    @ac615223s5

    on v1.68.1 it happens when a new directory has the same name as a file.

    Failed to copy: found file when looking for folder

  19. God-damnit-all commented on Apr 23, 2026

    @God-damnit-all

    on v1.68.1 it happens when a new directory has the same name as a file.

    Failed to copy: found file when looking for folder

    Sadly, rclone's MEGA implementation is loaded with issues that have persisted since its inception, the worst of which probably being lack of session caching. A large part of this is the service not only works a lot differently than most; so despite MEGA having an open-source C++ SDK with a compatible license (BSD-2), none of the maintainers as of yet have wanted to put in the kind of time a full implementation would take.

  20. added 2 commits that reference this issue on Aug 26, 2026
    435ea30
    5298b77
  21. XhstormR commented on Oct 4, 2026

    @XhstormR

    Yes, Mega has open-sourced its official client SDK: https://github.com/meganz/sdk . We need to implement a bridge layer between the Go and C++ implementations.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions