Skip to content

Commit

Permalink
review adjustments #2
Browse files Browse the repository at this point in the history
  • Loading branch information
powellnorma committed Jan 9, 2024
1 parent 931e169 commit 0360ef0
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions server_windows.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
//go:build go1.18

package sftp

import (
Expand Down Expand Up @@ -80,26 +78,33 @@ func (i *driveInfo) Name() string {

type winRoot struct {
dummyFile
doneDirs int
drives []string
}

func (f *winRoot) Readdir(n int) ([]os.FileInfo, error) {
func newWinRoot() (*winRoot, error) {
drives, err := getDrives()
if err != nil {
return nil, err
}
return &winRoot{
drives: drives,
}, nil
}

if f.doneDirs >= len(drives) {
return nil, io.EOF
func (f *winRoot) Readdir(n int) ([]os.FileInfo, error) {
drives := f.drives
if n > 0 {
if len(drives) > n {
drives = drives[:n]
}
f.drives = f.drives[len(drives):]
if len(drives) == 0 {
return nil, io.EOF
}
}
drives = drives[f.doneDirs:]

var infos []os.FileInfo
for i, drive := range drives {
if i >= n {
break
}

for _, drive := range drives {
fi, err := os.Stat(drive)
if err != nil {
return nil, err
Expand All @@ -112,13 +117,12 @@ func (f *winRoot) Readdir(n int) ([]os.FileInfo, error) {
infos = append(infos, di)
}

f.doneDirs += len(infos)
return infos, nil
}

func openfile(path string, flag int, mode fs.FileMode) (file, error) {
if path == "/" {
return &winRoot{}, nil
return newWinRoot()
}
return os.OpenFile(path, flag, mode)
}

0 comments on commit 0360ef0

Please sign in to comment.