2024-03-28 13:09:42 +00:00
|
|
|
package nfs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/willscott/go-nfs-client/nfs/xdr"
|
|
|
|
)
|
|
|
|
|
|
|
|
func onGetAttr(ctx context.Context, w *response, userHandle Handler) error {
|
|
|
|
handle, err := xdr.ReadOpaque(w.req.Body)
|
|
|
|
if err != nil {
|
|
|
|
return &NFSStatusError{NFSStatusInval, err}
|
|
|
|
}
|
|
|
|
|
|
|
|
fs, path, err := userHandle.FromHandle(handle)
|
|
|
|
if err != nil {
|
|
|
|
return &NFSStatusError{NFSStatusStale, err}
|
|
|
|
}
|
|
|
|
|
|
|
|
fullPath := fs.Join(path...)
|
|
|
|
info, err := fs.Lstat(ctx, fullPath)
|
|
|
|
if err != nil {
|
|
|
|
if os.IsNotExist(err) {
|
|
|
|
return &NFSStatusError{NFSStatusNoEnt, err}
|
|
|
|
}
|
|
|
|
if errors.Is(err, context.DeadlineExceeded) {
|
2024-04-06 13:51:17 +00:00
|
|
|
return &NFSStatusError{timeoutStatus, err}
|
2024-03-28 13:09:42 +00:00
|
|
|
}
|
|
|
|
return &NFSStatusError{NFSStatusIO, err}
|
|
|
|
}
|
|
|
|
attr := ToFileAttribute(info, fullPath)
|
|
|
|
|
|
|
|
writer := bytes.NewBuffer([]byte{})
|
|
|
|
if err := xdr.Write(writer, uint32(NFSStatusOk)); err != nil {
|
|
|
|
return &NFSStatusError{NFSStatusServerFault, err}
|
|
|
|
}
|
|
|
|
if err := xdr.Write(writer, attr); err != nil {
|
|
|
|
return &NFSStatusError{NFSStatusServerFault, err}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := w.Write(writer.Bytes()); err != nil {
|
|
|
|
return &NFSStatusError{NFSStatusServerFault, err}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|