You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Sync fails when a new file has the same name as an old directory #2231
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)
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?
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.
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.
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).
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.)
@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 :-)
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:
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.)
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!
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.
Activity
ncw commentedon Apr 12, 2018
NB note that using
--delete-beforeis a workaround for this issue.Yes I missed out those corer cases when writing the sync routine ;-)
Wheras rsync just overwrites it, no messing...
So that is what rclone should do I think
Interestingly rsync bombs out the other way round (which is your issue)
What do you think rclone should do?
Deleting a whole directory tree is quite unfriendly! (
rclone copyshould probably refuse to) Is there a flag which makesrsyncdelete a directory tree in the destination?anisse commentedon Apr 12, 2018
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.
eikenb commentedon Jun 15, 2018
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.
billdenney commentedon Aug 29, 2018
I just started encountering the same error mentioned above, and like @eikenb, I think that
syncshould 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
syncoperation, 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
syncis to make the destination look identical, but the user could override such that they are not identical (and those differences are warned when encountered).billdenney commentedon Sep 19, 2018
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.)ncw commentedon Sep 19, 2018
@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 :-)
billdenney commentedon Oct 27, 2018
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:
NoRetryErrorsince 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"))Rmdirfunction 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 ofpurge, andpurgeis already a recursive delete function.)ncw commentedon Oct 28, 2018
Yes that looks correct
operations.Purge is the correct thing to use as a recursive delete directory. Though if
--backup-diris in use then it should probably move the directory into the backup dir which will complicate things!ivandeex commentedon Nov 16, 2020
This issue seeks for volunteers.
ivandeex commentedon Feb 9, 2021
@anisse @billdenney This problem is reported against obsolete rclone version. Can you reproduce it with rclone 1.54?
2 remaining items
ivandeex commentedon Feb 9, 2021
@billdenney Thank you
Assigning as active bug report for fix.
cc @ncw
ac615223s5 commentedon Dec 20, 2024
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 folderGod-damnit-all commentedon Apr 23, 2026
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.
sync: replace conflicting files and directories
sync: replace conflicting files and directories
XhstormR commentedon Oct 4, 2026
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.