1
0
mirror of https://github.com/rclone/rclone.git synced 2026-01-13 05:53:16 +00:00

Compare commits

..

1 Commits

Author SHA1 Message Date
Nick Craig-Wood
6f86549ccb cmount: extra debug for #2187 2018-07-06 10:26:39 +01:00
11 changed files with 34 additions and 68 deletions

View File

@@ -480,7 +480,7 @@ func (f *Fs) list(dir string, recurse bool, fn listFn) (err error) {
remote := object.Name[rootLength:] remote := object.Name[rootLength:]
// is this a directory marker? // is this a directory marker?
if (strings.HasSuffix(remote, "/") || remote == "") && object.Size == 0 { if (strings.HasSuffix(remote, "/") || remote == "") && object.Size == 0 {
if recurse && remote != "" { if recurse {
// add a directory in if --fast-list since will have no prefixes // add a directory in if --fast-list since will have no prefixes
err = fn(remote[:len(remote)-1], object, true) err = fn(remote[:len(remote)-1], object, true)
if err != nil { if err != nil {

View File

@@ -864,7 +864,7 @@ func (f *Fs) list(dir string, recurse bool, fn listFn) error {
remote := key[rootLength:] remote := key[rootLength:]
// is this a directory marker? // is this a directory marker?
if (strings.HasSuffix(remote, "/") || remote == "") && *object.Size == 0 { if (strings.HasSuffix(remote, "/") || remote == "") && *object.Size == 0 {
if recurse && remote != "" { if recurse {
// add a directory in if --fast-list since will have no prefixes // add a directory in if --fast-list since will have no prefixes
remote = remote[:len(remote)-1] remote = remote[:len(remote)-1]
err = fn(remote, &s3.Object{Key: &remote}, true) err = fn(remote, &s3.Object{Key: &remote}, true)

View File

@@ -76,7 +76,7 @@ func init() {
Optional: true, Optional: true,
}, { }, {
Name: "use_insecure_cipher", Name: "use_insecure_cipher",
Help: "Enable the use of the aes128-cbc cipher. This cipher is insecure and may allow plaintext data to be recovered by an attacker.", Help: "Enable the user of the aes128-cbc cipher. This cipher is insecure and may allow plaintext data to be recovered by an attacker.",
Optional: true, Optional: true,
Examples: []fs.OptionExample{ Examples: []fs.OptionExample{
{ {

View File

@@ -245,7 +245,7 @@ func NewFsSrcDstFiles(args []string) (fsrc fs.Fs, srcFileName string, fdst fs.Fs
// If file exists then srcFileName != "", however if the file // If file exists then srcFileName != "", however if the file
// doesn't exist then we assume it is a directory... // doesn't exist then we assume it is a directory...
if srcFileName != "" { if srcFileName != "" {
dstRemote, dstFileName = fspath.Split(dstRemote) dstRemote, dstFileName = fspath.RemoteSplit(dstRemote)
if dstRemote == "" { if dstRemote == "" {
dstRemote = "." dstRemote = "."
} }
@@ -268,7 +268,7 @@ func NewFsSrcDstFiles(args []string) (fsrc fs.Fs, srcFileName string, fdst fs.Fs
// NewFsDstFile creates a new dst fs with a destination file name from the arguments // NewFsDstFile creates a new dst fs with a destination file name from the arguments
func NewFsDstFile(args []string) (fdst fs.Fs, dstFileName string) { func NewFsDstFile(args []string) (fdst fs.Fs, dstFileName string) {
dstRemote, dstFileName := fspath.Split(args[0]) dstRemote, dstFileName := fspath.RemoteSplit(args[0])
if dstRemote == "" { if dstRemote == "" {
dstRemote = "." dstRemote = "."
} }

View File

@@ -192,7 +192,7 @@ func (fsys *FS) Destroy() {
// Getattr reads the attributes for path // Getattr reads the attributes for path
func (fsys *FS) Getattr(path string, stat *fuse.Stat_t, fh uint64) (errc int) { func (fsys *FS) Getattr(path string, stat *fuse.Stat_t, fh uint64) (errc int) {
defer log.Trace(path, "fh=0x%X", fh)("errc=%v", &errc) defer log.Trace(path, "fh=0x%X", fh)("stat=%+v, errc=%v", &stat, &errc)
node, _, errc := fsys.getNode(path, fh) node, _, errc := fsys.getNode(path, fh)
if errc == 0 { if errc == 0 {
errc = fsys.stat(node, stat) errc = fsys.stat(node, stat)

View File

@@ -79,9 +79,6 @@ func (f *File) Open(ctx context.Context, req *fuse.OpenRequest, resp *fuse.OpenR
resp.Flags |= fuse.OpenNonSeekable resp.Flags |= fuse.OpenNonSeekable
} }
// Keep the file in the cache - equivalent of kernel_cache
resp.Flags |= fuse.OpenKeepCache
return &FileHandle{handle}, nil return &FileHandle{handle}, nil
} }

View File

@@ -170,4 +170,3 @@ Contributors
* Benjamin Joseph Dag <bjdag1234@users.noreply.github.com> * Benjamin Joseph Dag <bjdag1234@users.noreply.github.com>
* themylogin <themylogin@gmail.com> * themylogin <themylogin@gmail.com>
* Onno Zweers <onno.zweers@surfsara.nl> * Onno Zweers <onno.zweers@surfsara.nl>
* Jasper Lievisse Adriaanse <jasper@humppa.nl>

View File

@@ -30,7 +30,6 @@ import (
"github.com/ncw/rclone/fs/config/obscure" "github.com/ncw/rclone/fs/config/obscure"
"github.com/ncw/rclone/fs/driveletter" "github.com/ncw/rclone/fs/driveletter"
"github.com/ncw/rclone/fs/fshttp" "github.com/ncw/rclone/fs/fshttp"
"github.com/ncw/rclone/fs/fspath"
"github.com/pkg/errors" "github.com/pkg/errors"
"golang.org/x/crypto/nacl/secretbox" "golang.org/x/crypto/nacl/secretbox"
"golang.org/x/text/unicode/norm" "golang.org/x/text/unicode/norm"
@@ -866,12 +865,12 @@ func NewRemoteName() (name string) {
for { for {
fmt.Printf("name> ") fmt.Printf("name> ")
name = ReadLine() name = ReadLine()
parts := fspath.Matcher.FindStringSubmatch(name + ":") parts := fs.Matcher.FindStringSubmatch(name + ":")
switch { switch {
case name == "": case name == "":
fmt.Printf("Can't use empty name.\n") fmt.Printf("Can't use empty name.\n")
case driveletter.IsDriveLetter(name): case driveletter.IsDriveLetter(name):
fmt.Printf("Can't use %q as it can be confused with a drive letter.\n", name) fmt.Printf("Can't use %q as it can be confused a drive letter.\n", name)
case parts == nil: case parts == nil:
fmt.Printf("Can't use %q as it has invalid characters in it.\n", name) fmt.Printf("Can't use %q as it has invalid characters in it.\n", name)
default: default:

View File

@@ -9,11 +9,12 @@ import (
"os" "os"
"path/filepath" "path/filepath"
"reflect" "reflect"
"regexp"
"sort" "sort"
"strings" "strings"
"time" "time"
"github.com/ncw/rclone/fs/fspath" "github.com/ncw/rclone/fs/driveletter"
"github.com/ncw/rclone/fs/hash" "github.com/ncw/rclone/fs/hash"
"github.com/pkg/errors" "github.com/pkg/errors"
) )
@@ -785,20 +786,24 @@ func MustFind(name string) *RegInfo {
return fs return fs
} }
// Matcher is a pattern to match an rclone URL
var Matcher = regexp.MustCompile(`^([\w_ -]+):(.*)$`)
// ParseRemote deconstructs a path into configName, fsPath, looking up // ParseRemote deconstructs a path into configName, fsPath, looking up
// the fsName in the config file (returning NotFoundInConfigFile if not found) // the fsName in the config file (returning NotFoundInConfigFile if not found)
func ParseRemote(path string) (fsInfo *RegInfo, configName, fsPath string, err error) { func ParseRemote(path string) (fsInfo *RegInfo, configName, fsPath string, err error) {
configName, fsPath = fspath.Parse(path) parts := Matcher.FindStringSubmatch(path)
var fsName string var fsName string
if configName != "" { fsName, configName, fsPath = "local", "local", path
if parts != nil && !driveletter.IsDriveLetter(parts[1]) {
configName, fsPath = parts[1], parts[2]
fsName = ConfigFileGet(configName, "type") fsName = ConfigFileGet(configName, "type")
if fsName == "" { if fsName == "" {
return nil, "", "", ErrorNotFoundInConfigFile return nil, "", "", ErrorNotFoundInConfigFile
} }
} else {
fsName = "local"
configName = "local"
} }
// change native directory separators to / if there are any
fsPath = filepath.ToSlash(fsPath)
fsInfo, err = Find(fsName) fsInfo, err = Find(fsName)
return fsInfo, configName, fsPath, err return fsInfo, configName, fsPath, err
} }

View File

@@ -3,46 +3,27 @@ package fspath
import ( import (
"path" "path"
"path/filepath" "strings"
"regexp"
"github.com/ncw/rclone/fs/driveletter"
) )
// Matcher is a pattern to match an rclone URL // RemoteSplit splits a remote into a parent and a leaf
var Matcher = regexp.MustCompile(`^([\w_ -]+):(.*)$`)
// Parse deconstructs a remote path into configName and fsPath
//
// If the path is a local path then configName will be returned as "".
//
// So "remote:path/to/dir" will return "remote", "path/to/dir"
// and "/path/to/local" will return ("", "/path/to/local")
//
// Note that this will turn \ into / in the fsPath on Windows
func Parse(path string) (configName, fsPath string) {
parts := Matcher.FindStringSubmatch(path)
configName, fsPath = "", path
if parts != nil && !driveletter.IsDriveLetter(parts[1]) {
configName, fsPath = parts[1], parts[2]
}
// change native directory separators to / if there are any
fsPath = filepath.ToSlash(fsPath)
return configName, fsPath
}
// Split splits a remote into a parent and a leaf
// //
// if it returns leaf as an empty string then remote is a directory // if it returns leaf as an empty string then remote is a directory
// //
// if it returns parent as an empty string then that means the current directory // if it returns parent as an empty string then that means the current directory
// //
// The returned values have the property that parent + leaf == remote // The returned values have the property that parent + leaf == remote
// (except under Windows where \ will be translated into /) func RemoteSplit(remote string) (parent string, leaf string) {
func Split(remote string) (parent string, leaf string) { // Split remote on :
remoteName, remotePath := Parse(remote) i := strings.Index(remote, ":")
if remoteName != "" { remoteName := ""
remoteName += ":" remotePath := remote
if i >= 0 {
remoteName = remote[:i+1]
remotePath = remote[i+1:]
} else if strings.HasSuffix(remotePath, "/") {
// if no : and ends with / must be directory
return remotePath, ""
} }
// Construct new remote name without last segment // Construct new remote name without last segment
parent, leaf = path.Split(remotePath) parent, leaf = path.Split(remotePath)

View File

@@ -7,23 +7,8 @@ import (
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
) )
func TestParse(t *testing.T) { func TestRemoteSplit(t *testing.T) {
for _, test := range []struct {
in, wantConfigName, wantFsPath string
}{
{"", "", ""},
{"/path/to/file", "", "/path/to/file"},
{"path/to/file", "", "path/to/file"},
{"remote:path/to/file", "remote", "path/to/file"},
{"remote:/path/to/file", "remote", "/path/to/file"},
} {
gotConfigName, gotFsPath := Parse(test.in)
assert.Equal(t, test.wantConfigName, gotConfigName)
assert.Equal(t, test.wantFsPath, gotFsPath)
}
}
func TestSplit(t *testing.T) {
for _, test := range []struct { for _, test := range []struct {
remote, wantParent, wantLeaf string remote, wantParent, wantLeaf string
}{ }{
@@ -42,7 +27,7 @@ func TestSplit(t *testing.T) {
{"root/", "root/", ""}, {"root/", "root/", ""},
{"a/b/", "a/b/", ""}, {"a/b/", "a/b/", ""},
} { } {
gotParent, gotLeaf := Split(test.remote) gotParent, gotLeaf := RemoteSplit(test.remote)
assert.Equal(t, test.wantParent, gotParent, test.remote) assert.Equal(t, test.wantParent, gotParent, test.remote)
assert.Equal(t, test.wantLeaf, gotLeaf, test.remote) assert.Equal(t, test.wantLeaf, gotLeaf, test.remote)
assert.Equal(t, test.remote, gotParent+gotLeaf, fmt.Sprintf("%s: %q + %q != %q", test.remote, gotParent, gotLeaf, test.remote)) assert.Equal(t, test.remote, gotParent+gotLeaf, fmt.Sprintf("%s: %q + %q != %q", test.remote, gotParent, gotLeaf, test.remote))