mirror of https://github.com/spf13/afero.git
rclone: new readfile
This commit is contained in:
parent
71e5cee5db
commit
d3cdf0c871
114
rclonefs/fs.go
114
rclonefs/fs.go
|
@ -2,15 +2,18 @@ package rclonefs
|
|||
|
||||
import (
|
||||
"context"
|
||||
"os"
|
||||
"os/user"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
_ "github.com/rclone/rclone/backend/all"
|
||||
"github.com/rclone/rclone/fs"
|
||||
"github.com/rclone/rclone/fs/config"
|
||||
"github.com/rclone/rclone/fs/config/configfile"
|
||||
"github.com/rclone/rclone/vfs"
|
||||
"github.com/spf13/afero"
|
||||
)
|
||||
|
||||
type RCFS struct {
|
||||
|
@ -45,3 +48,114 @@ func CreateRCFS(path string) (*RCFS, error) {
|
|||
|
||||
return &RCFS{Fs: vfs, Cwd: cwd}, nil
|
||||
}
|
||||
|
||||
func (rcfs *RCFS) AbsPath(name string) string {
|
||||
if !filepath.IsAbs(name) {
|
||||
name = filepath.Join(rcfs.Cwd, name)
|
||||
}
|
||||
|
||||
return name
|
||||
}
|
||||
|
||||
func (rcfs *RCFS) Name() string { return "RClone virtual filesystem" }
|
||||
|
||||
func (rcfs *RCFS) Create(name string) (afero.File, error) {
|
||||
name = rcfs.AbsPath(name)
|
||||
|
||||
return rcfs.Fs.Create(name)
|
||||
}
|
||||
|
||||
func (rcfs *RCFS) Mkdir(name string, perm os.FileMode) error {
|
||||
// TODO
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rcfs *RCFS) MkdirAll(name string, perm os.FileMode) error {
|
||||
// TODO
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rcfs *RCFS) Open(name string) (afero.File, error) {
|
||||
name = rcfs.AbsPath(name)
|
||||
|
||||
f, e := rcfs.Fs.Open(name)
|
||||
if f == nil {
|
||||
return nil, e
|
||||
}
|
||||
return f, e
|
||||
}
|
||||
|
||||
func (rcfs *RCFS) OpenFile(name string, flag int, perm os.FileMode) (afero.File, error) {
|
||||
name = rcfs.AbsPath(name)
|
||||
|
||||
return rcfs.Fs.OpenFile(name, flag, perm)
|
||||
}
|
||||
|
||||
func (rcfs *RCFS) Stat(name string) (os.FileInfo, error) {
|
||||
name = rcfs.AbsPath(name)
|
||||
|
||||
return rcfs.Fs.Stat(name)
|
||||
}
|
||||
|
||||
func (rcfs *RCFS) Remove(name string) error {
|
||||
name = rcfs.AbsPath(name)
|
||||
|
||||
return rcfs.Fs.Remove(name)
|
||||
}
|
||||
|
||||
func (rcfs *RCFS) RemoveAll(path string) error {
|
||||
// TODO
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rcfs *RCFS) Rename(oldname, newname string) error {
|
||||
oldname = rcfs.AbsPath(oldname)
|
||||
newname = rcfs.AbsPath(newname)
|
||||
|
||||
return rcfs.Fs.Rename(oldname, newname)
|
||||
}
|
||||
|
||||
func (rcfs *RCFS) Chmod(name string, mode os.FileMode) error {
|
||||
// TODO
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rcfs *RCFS) Chown(name string, uid, gid int) error {
|
||||
// TODO
|
||||
return nil
|
||||
}
|
||||
|
||||
func (rcfs *RCFS) Chtimes(name string, atime time.Time, mtime time.Time) error {
|
||||
name = rcfs.AbsPath(name)
|
||||
|
||||
return rcfs.Fs.Chtimes(name, atime, mtime)
|
||||
}
|
||||
|
||||
func (rcfs *RCFS) ReadFile(name string) ([]byte, error) {
|
||||
name = rcfs.AbsPath(name)
|
||||
|
||||
return rcfs.Fs.ReadFile(name)
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -2,12 +2,19 @@ package main
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
|
||||
"github.com/spf13/afero/rclonefs"
|
||||
)
|
||||
|
||||
func main() {
|
||||
newrc, _ := rclonefs.CreateRCFS("godrive1:")
|
||||
RFS, _ := rclonefs.CreateRCFS("godrive1:")
|
||||
|
||||
fmt.Println(newrc)
|
||||
data, err := RFS.ReadFile("mock.json")
|
||||
if err != nil {
|
||||
fmt.Printf("Error: %v\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
fmt.Printf("%s\n", string(data))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue