From 0d4bff8239e7852c6c5bc3b820f5691ad8e89271 Mon Sep 17 00:00:00 2001 From: remusb Date: Wed, 20 Dec 2017 17:24:50 +0200 Subject: [PATCH] cache: fix Windows separator issue for #1904 (#1930) --- cache/directory.go | 8 ++++---- cache/object.go | 7 ++++--- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/cache/directory.go b/cache/directory.go index d137e5869..3457aa2ad 100644 --- a/cache/directory.go +++ b/cache/directory.go @@ -5,9 +5,7 @@ package cache import ( "time" - "os" "path" - "strings" "github.com/ncw/rclone/fs" ) @@ -97,8 +95,10 @@ func (d *Directory) String() string { func (d *Directory) Remote() string { p := cleanPath(path.Join(d.Dir, d.Name)) if d.CacheFs.Root() != "" { - p = strings.Replace(p, d.CacheFs.Root(), "", 1) - p = strings.TrimPrefix(p, string(os.PathSeparator)) + p = p[len(d.CacheFs.Root()):] // trim out root + if len(p) > 0 { // remove first separator + p = p[1:] + } } return p diff --git a/cache/object.go b/cache/object.go index ceed9f583..184730b31 100644 --- a/cache/object.go +++ b/cache/object.go @@ -7,7 +7,6 @@ import ( "io" "os" "path" - "strings" "sync" "time" @@ -133,8 +132,10 @@ func (o *Object) String() string { func (o *Object) Remote() string { p := path.Join(o.Dir, o.Name) if o.CacheFs.Root() != "" { - p = strings.Replace(p, o.CacheFs.Root(), "", 1) - p = strings.TrimPrefix(p, string(os.PathSeparator)) + p = p[len(o.CacheFs.Root()):] // trim out root + if len(p) > 0 { // remove first separator + p = p[1:] + } } return p