mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 09:11:11 +08:00
vfs: fix OS vs Unix path confusion - fixes ChangeNotify on Windows
See: https://forum.rclone.org/t/windows-mount-polling-not-recognising-all-changes-made-by-another-box/16708
This commit is contained in:
parent
151f03378f
commit
50e31c6636
|
@ -4,6 +4,7 @@ package vfscache
|
|||
import (
|
||||
"context"
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sort"
|
||||
|
@ -78,9 +79,11 @@ func New(ctx context.Context, fremote fs.Fs, opt *vfscommon.Options) (*Cache, er
|
|||
}
|
||||
|
||||
// clean returns the cleaned version of name for use in the index map
|
||||
//
|
||||
// name should be a remote path not an osPath
|
||||
func clean(name string) string {
|
||||
name = strings.Trim(name, "/")
|
||||
name = filepath.Clean(name)
|
||||
name = path.Clean(name)
|
||||
if name == "." || name == "/" {
|
||||
name = ""
|
||||
}
|
||||
|
@ -94,9 +97,11 @@ func (c *Cache) ToOSPath(name string) string {
|
|||
|
||||
// Mkdir makes the directory for name in the cache and returns an os
|
||||
// path for the file
|
||||
//
|
||||
// name should be a remote path not an osPath
|
||||
func (c *Cache) Mkdir(name string) (string, error) {
|
||||
parent := vfscommon.FindParent(name)
|
||||
leaf := filepath.Base(name)
|
||||
leaf := path.Base(name)
|
||||
parentPath := c.ToOSPath(parent)
|
||||
err := os.MkdirAll(parentPath, 0700)
|
||||
if err != nil {
|
||||
|
@ -244,7 +249,7 @@ func (c *Cache) Rename(name string, newName string) (err error) {
|
|||
if !os.IsNotExist(err) {
|
||||
return errors.Wrapf(err, "Failed to stat destination: %s", osNewPath)
|
||||
}
|
||||
parent := vfscommon.FindParent(osNewPath)
|
||||
parent := vfscommon.OsFindParent(osNewPath)
|
||||
err = os.MkdirAll(parent, 0700)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "Failed to create parent dir: %s", parent)
|
||||
|
|
|
@ -1,12 +1,26 @@
|
|||
package vfscommon
|
||||
|
||||
import "path/filepath"
|
||||
import (
|
||||
"path"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// FindParent returns the parent directory of name, or "" for the root
|
||||
func FindParent(name string) string {
|
||||
// OsFindParent returns the parent directory of name, or "" for the
|
||||
// root for OS native paths.
|
||||
func OsFindParent(name string) string {
|
||||
parent := filepath.Dir(name)
|
||||
if parent == "." || parent == "/" {
|
||||
parent = ""
|
||||
}
|
||||
return parent
|
||||
}
|
||||
|
||||
// FindParent returns the parent directory of name, or "" for the root
|
||||
// for rclone paths.
|
||||
func FindParent(name string) string {
|
||||
parent := path.Dir(name)
|
||||
if parent == "." || parent == "/" {
|
||||
parent = ""
|
||||
}
|
||||
return parent
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user