Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

cache: fix Windows separator issue for #1904 (#1930)

remusb0d4bff8239e7
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