RemoveAll started, slash fixed

This commit is contained in:
mkvolkov 2022-08-20 11:18:41 +03:00
parent 259d3109dc
commit 0c3bf314c5
2 changed files with 39 additions and 10 deletions

View File

@ -2,6 +2,8 @@ package rclonefs
import ( import (
"context" "context"
"fmt"
"io/fs"
"os" "os"
"os/user" "os/user"
"path/filepath" "path/filepath"
@ -9,7 +11,7 @@ import (
"time" "time"
_ "github.com/rclone/rclone/backend/all" _ "github.com/rclone/rclone/backend/all"
"github.com/rclone/rclone/fs" rclfs "github.com/rclone/rclone/fs"
"github.com/rclone/rclone/fs/config" "github.com/rclone/rclone/fs/config"
"github.com/rclone/rclone/fs/config/configfile" "github.com/rclone/rclone/fs/config/configfile"
"github.com/rclone/rclone/vfs" "github.com/rclone/rclone/vfs"
@ -38,8 +40,9 @@ func CreateRCFS(path string) (*RCFS, error) {
rootdir, cwd, _ := strings.Cut(path, ":") rootdir, cwd, _ := strings.Cut(path, ":")
rootdir += ":" rootdir += ":"
cwd = filepath.Join("/", cwd)
rfs, e := fs.NewFs(context.Background(), rootdir) rfs, e := rclfs.NewFs(context.Background(), rootdir)
if e != nil { if e != nil {
return nil, e return nil, e
} }
@ -104,7 +107,9 @@ func (rcfs *RCFS) Remove(name string) error {
} }
func (rcfs *RCFS) RemoveAll(path string) error { func (rcfs *RCFS) RemoveAll(path string) error {
// TODO path = rcfs.AbsPath(path)
afero.Walk(rcfs, path, printNode)
return nil return nil
} }
@ -131,8 +136,32 @@ func (rcfs *RCFS) Chtimes(name string, atime time.Time, mtime time.Time) error {
return rcfs.Fs.Chtimes(name, atime, mtime) return rcfs.Fs.Chtimes(name, atime, mtime)
} }
func printNode(path string, info fs.FileInfo, err error) error {
if err != nil {
fmt.Printf("prevent panic by handling failure accessing a path %q: %v\n", path, err)
return err
}
if info.IsDir() {
fmt.Printf("visited dir: %q\n", path)
return nil
} else {
fmt.Printf("visited file: %q\n", path)
return nil
}
}
/*
func rmNode(path string, info fs.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
return nil
} else {
a
}
}
*/

View File

@ -4,18 +4,18 @@ import (
"fmt" "fmt"
"os" "os"
"github.com/spf13/afero" // "github.com/spf13/afero"
"github.com/spf13/afero/rclonefs" "github.com/spf13/afero/rclonefs"
) )
func main() { func main() {
RFS, _ := rclonefs.CreateRCFS("godrive1:") RFS, _ := rclonefs.CreateRCFS("pcloud_mv1:cfg")
data, err := afero.ReadFile(RFS, "mock.json") name := "ycfg"
err := RFS.RemoveAll(name)
if err != nil { if err != nil {
fmt.Printf("Error: %v\n", err) fmt.Printf("Error: %v\n", err)
os.Exit(1) os.Exit(1)
} }
fmt.Printf("%s\n", string(data))
} }