fs: Allow sync of a file and a directory with the same name

When sorting fs.DirEntries we sort by DirEntry type and
when synchronizing files let the directories be before objects,
so when the destintation fs doesn't support duplicate names,
we will only lose duplicated object instead of whole directory.

The enables synchronisation to work with a file and a directory of the same name
which is reasonably common on bucket based remotes.
This commit is contained in:
forgems 2019-06-09 16:57:05 +02:00 committed by Nick Craig-Wood
parent fb6966b5fe
commit 4b27c6719b
4 changed files with 161 additions and 36 deletions

26
fs/direntries_test.go Normal file
View file

@ -0,0 +1,26 @@
package fs_test
import (
"sort"
"testing"
"github.com/ncw/rclone/fs"
"github.com/ncw/rclone/fstest/mockdir"
"github.com/ncw/rclone/fstest/mockobject"
"github.com/stretchr/testify/assert"
)
func TestDirEntriesSort(t *testing.T) {
a := mockobject.New("a")
aDir := mockdir.New("a")
b := mockobject.New("b")
bDir := mockdir.New("b")
c := mockobject.New("c")
cDir := mockdir.New("c")
anotherc := mockobject.New("c")
dirEntries := fs.DirEntries{bDir, b, aDir, a, c, cDir, anotherc}
sort.Stable(dirEntries)
assert.Equal(t, fs.DirEntries{aDir, a, bDir, b, cDir, c, anotherc}, dirEntries)
}