Skip to content

Commit

Permalink
Use an lstat rather than a readDir for lookups
Browse files Browse the repository at this point in the history
fix #119
  • Loading branch information
willscott committed Jan 4, 2024
1 parent 891f4cd commit 9a6953f
Showing 1 changed file with 14 additions and 18 deletions.
32 changes: 14 additions & 18 deletions nfs_onlookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ func onLookup(ctx context.Context, w *response, userHandle Handler) error {
if err != nil {
return &NFSStatusError{NFSStatusStale, err}
}
contents, err := fs.ReadDir(fs.Join(p...))
if err != nil {
dirInfo, err := fs.Lstat(fs.Join(p...))
if err != nil || !dirInfo.IsDir() {
return &NFSStatusError{NFSStatusNotDir, err}
}

Expand Down Expand Up @@ -70,22 +70,18 @@ func onLookup(ctx context.Context, w *response, userHandle Handler) error {
return nil
}

// TODO: use sorting rather than linear
for _, f := range contents {
if bytes.Equal([]byte(f.Name()), obj.Filename) {
newPath := append(p, f.Name())
newHandle := userHandle.ToHandle(fs, newPath)
resp, err := lookupSuccessResponse(newHandle, newPath, p, fs)
if err != nil {
return &NFSStatusError{NFSStatusServerFault, err}
}
if err := w.Write(resp); err != nil {
return &NFSStatusError{NFSStatusServerFault, err}
}
return nil
}
reqPath := append(p, string(obj.Filename))
if _, err = fs.Lstat(fs.Join(reqPath...)); err != nil {
return &NFSStatusError{NFSStatusNoEnt, os.ErrNotExist}
}

Log.Errorf("No file for lookup of %v\n", string(obj.Filename))
return &NFSStatusError{NFSStatusNoEnt, os.ErrNotExist}
newHandle := userHandle.ToHandle(fs, reqPath)
resp, err := lookupSuccessResponse(newHandle, reqPath, p, fs)
if err != nil {
return &NFSStatusError{NFSStatusServerFault, err}
}
if err := w.Write(resp); err != nil {
return &NFSStatusError{NFSStatusServerFault, err}
}
return nil
}

0 comments on commit 9a6953f

Please sign in to comment.