Skip to content

Commit

Permalink
sftpfs Readdirnames,Readdir
Browse files Browse the repository at this point in the history
  • Loading branch information
lixiangzhong committed May 27, 2021
1 parent bc94f58 commit 5dc5331
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 9 deletions.
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190412213103-97732733099d h1:+R4KGOnez64A81RvjARKc4UT5/tI9ujCIVX+P5KiHuI=
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
Expand Down
32 changes: 24 additions & 8 deletions sftpfs/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,30 @@
package sftpfs

import (
"github.com/pkg/sftp"
"os"

"github.com/pkg/sftp"
)

type File struct {
fd *sftp.File
client *sftp.Client
fd *sftp.File
}

func FileOpen(s *sftp.Client, name string) (*File, error) {
fd, err := s.Open(name)
if err != nil {
return &File{}, err
}
return &File{fd: fd}, nil
return &File{fd: fd, client: s}, nil
}

func FileCreate(s *sftp.Client, name string) (*File, error) {
fd, err := s.Create(name)
if err != nil {
return &File{}, err
}
return &File{fd: fd}, nil
return &File{fd: fd, client: s}, nil
}

func (f *File) Close() error {
Expand Down Expand Up @@ -67,14 +69,28 @@ func (f *File) ReadAt(b []byte, off int64) (n int, err error) {
return 0, nil
}

// TODO
func (f *File) Readdir(count int) (res []os.FileInfo, err error) {
return nil, nil
res, err = f.client.ReadDir(f.Name())
if err != nil {
return
}
if count > 0 {
if len(res) > count {
res = res[:count]
}
}
return
}

// TODO
func (f *File) Readdirnames(n int) (names []string, err error) {
return nil, nil
data, err := f.Readdir(n)
if err != nil {
return nil, err
}
for _, v := range data {
names = append(names, v.Name())
}
return
}

func (f *File) Seek(offset int64, whence int) (int64, error) {
Expand Down

0 comments on commit 5dc5331

Please sign in to comment.