mirror of https://github.com/rclone/rclone.git
tree: fix when running under Windows
This commit is contained in:
parent
214f5e6411
commit
21aca68680
|
@ -6,6 +6,7 @@ import (
|
||||||
"log"
|
"log"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
@ -195,6 +196,7 @@ func NewFs(dirs fs.DirTree) Fs {
|
||||||
// Stat returns info about the file
|
// Stat returns info about the file
|
||||||
func (dirs Fs) Stat(filePath string) (fi os.FileInfo, err error) {
|
func (dirs Fs) Stat(filePath string) (fi os.FileInfo, err error) {
|
||||||
defer fs.Trace(nil, "filePath=%q", filePath)("fi=%+v, err=%v", &fi, &err)
|
defer fs.Trace(nil, "filePath=%q", filePath)("fi=%+v, err=%v", &fi, &err)
|
||||||
|
filePath = filepath.ToSlash(filePath)
|
||||||
filePath = strings.TrimLeft(filePath, "/")
|
filePath = strings.TrimLeft(filePath, "/")
|
||||||
if filePath == "" {
|
if filePath == "" {
|
||||||
return &FileInfo{fs.NewDir("", time.Now())}, nil
|
return &FileInfo{fs.NewDir("", time.Now())}, nil
|
||||||
|
@ -209,6 +211,7 @@ func (dirs Fs) Stat(filePath string) (fi os.FileInfo, err error) {
|
||||||
// ReadDir returns info about the directory and fills up the directory cache
|
// ReadDir returns info about the directory and fills up the directory cache
|
||||||
func (dirs Fs) ReadDir(dir string) (names []string, err error) {
|
func (dirs Fs) ReadDir(dir string) (names []string, err error) {
|
||||||
defer fs.Trace(nil, "dir=%s", dir)("names=%+v, err=%v", &names, &err)
|
defer fs.Trace(nil, "dir=%s", dir)("names=%+v, err=%v", &names, &err)
|
||||||
|
dir = filepath.ToSlash(dir)
|
||||||
dir = strings.TrimLeft(dir, "/")
|
dir = strings.TrimLeft(dir, "/")
|
||||||
entries, ok := dirs[dir]
|
entries, ok := dirs[dir]
|
||||||
if !ok {
|
if !ok {
|
||||||
|
|
|
@ -6,6 +6,7 @@ import (
|
||||||
|
|
||||||
"github.com/a8m/tree"
|
"github.com/a8m/tree"
|
||||||
"github.com/ncw/rclone/fs"
|
"github.com/ncw/rclone/fs"
|
||||||
|
"github.com/ncw/rclone/fstest"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
"github.com/stretchr/testify/require"
|
"github.com/stretchr/testify/require"
|
||||||
|
|
||||||
|
@ -13,12 +14,10 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestTree(t *testing.T) {
|
func TestTree(t *testing.T) {
|
||||||
|
fstest.Initialise()
|
||||||
|
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
// Never ask for passwords, fail instead.
|
|
||||||
// If your local config is encrypted set environment variable
|
|
||||||
// "RCLONE_CONFIG_PASS=hunter2" (or your password)
|
|
||||||
*fs.AskPassword = false
|
|
||||||
fs.LoadConfig()
|
|
||||||
f, err := fs.NewFs("testfiles")
|
f, err := fs.NewFs("testfiles")
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
err = Tree(f, buf, new(tree.Options))
|
err = Tree(f, buf, new(tree.Options))
|
||||||
|
|
Loading…
Reference in New Issue