forked from mirror/afero
sftpfs Readdirnames,Readdir
This commit is contained in:
parent
bc94f58bed
commit
5dc5331f47
1
go.sum
1
go.sum
|
@ -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=
|
||||
|
|
|
@ -14,11 +14,13 @@
|
|||
package sftpfs
|
||||
|
||||
import (
|
||||
"github.com/pkg/sftp"
|
||||
"os"
|
||||
|
||||
"github.com/pkg/sftp"
|
||||
)
|
||||
|
||||
type File struct {
|
||||
client *sftp.Client
|
||||
fd *sftp.File
|
||||
}
|
||||
|
||||
|
@ -27,7 +29,7 @@ func FileOpen(s *sftp.Client, name string) (*File, error) {
|
|||
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) {
|
||||
|
@ -35,7 +37,7 @@ func FileCreate(s *sftp.Client, name string) (*File, error) {
|
|||
if err != nil {
|
||||
return &File{}, err
|
||||
}
|
||||
return &File{fd: fd}, nil
|
||||
return &File{fd: fd, client: s}, nil
|
||||
}
|
||||
|
||||
func (f *File) Close() error {
|
||||
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue