2024-03-28 13:09:42 +00:00
|
|
|
package nfs
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"context"
|
|
|
|
"errors"
|
|
|
|
"os"
|
|
|
|
|
|
|
|
"github.com/willscott/go-nfs-client/nfs/xdr"
|
|
|
|
)
|
|
|
|
|
|
|
|
func onReadLink(ctx context.Context, w *response, userHandle Handler) error {
|
|
|
|
w.errorFmt = opAttrErrorFormatter
|
|
|
|
handle, err := xdr.ReadOpaque(w.req.Body)
|
|
|
|
if err != nil {
|
|
|
|
return &NFSStatusError{NFSStatusInval, err}
|
|
|
|
}
|
2024-06-16 21:34:46 +00:00
|
|
|
fs, path, err := userHandle.FromHandle(ctx, handle)
|
2024-03-28 13:09:42 +00:00
|
|
|
if err != nil {
|
|
|
|
return &NFSStatusError{NFSStatusStale, err}
|
|
|
|
}
|
|
|
|
|
|
|
|
out, err := fs.Readlink(ctx, fs.Join(path...))
|
|
|
|
if err != nil {
|
|
|
|
if info, err := fs.Stat(ctx, fs.Join(path...)); err == nil {
|
|
|
|
if info.Mode()&os.ModeSymlink == 0 {
|
|
|
|
return &NFSStatusError{NFSStatusInval, err}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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{NFSStatusAccess, err}
|
|
|
|
}
|
|
|
|
|
|
|
|
writer := bytes.NewBuffer([]byte{})
|
|
|
|
if err := xdr.Write(writer, uint32(NFSStatusOk)); err != nil {
|
|
|
|
return &NFSStatusError{NFSStatusServerFault, err}
|
|
|
|
}
|
|
|
|
if err := WritePostOpAttrs(writer, tryStat(ctx, fs, path)); err != nil {
|
|
|
|
return &NFSStatusError{NFSStatusServerFault, err}
|
|
|
|
}
|
|
|
|
|
|
|
|
if err := xdr.Write(writer, out); err != nil {
|
|
|
|
return &NFSStatusError{NFSStatusServerFault, err}
|
|
|
|
}
|
|
|
|
if err := w.Write(writer.Bytes()); err != nil {
|
|
|
|
return &NFSStatusError{NFSStatusServerFault, err}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|