small refactor*
This commit is contained in:
parent
b6b541e050
commit
24a4d30275
232 changed files with 2164 additions and 1906 deletions
server/pkg/go-nfs
51
server/pkg/go-nfs/nfs_oncommit.go
Normal file
51
server/pkg/go-nfs/nfs_oncommit.go
Normal file
|
@ -0,0 +1,51 @@
|
|||
package nfs
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"os"
|
||||
|
||||
billy "github.com/go-git/go-billy/v5"
|
||||
"github.com/willscott/go-nfs-client/nfs/xdr"
|
||||
)
|
||||
|
||||
// onCommit - note this is a no-op, as we always push writes to the backing store.
|
||||
func onCommit(ctx context.Context, w *response, userHandle Handler) error {
|
||||
w.errorFmt = wccDataErrorFormatter
|
||||
handle, err := xdr.ReadOpaque(w.req.Body)
|
||||
if err != nil {
|
||||
return &NFSStatusError{NFSStatusInval, err}
|
||||
}
|
||||
// The conn will drain the unread offset and count arguments.
|
||||
|
||||
fs, path, err := userHandle.FromHandle(ctx, handle)
|
||||
if err != nil {
|
||||
return &NFSStatusError{NFSStatusStale, err}
|
||||
}
|
||||
|
||||
if !CapabilityCheck(fs, billy.WriteCapability) {
|
||||
return &NFSStatusError{NFSStatusServerFault, os.ErrPermission}
|
||||
}
|
||||
|
||||
writer := bytes.NewBuffer([]byte{})
|
||||
if err := xdr.Write(writer, uint32(NFSStatusOk)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// no pre-op cache data.
|
||||
if err := xdr.Write(writer, uint32(0)); err != nil {
|
||||
return &NFSStatusError{NFSStatusServerFault, err}
|
||||
}
|
||||
if err := WritePostOpAttrs(writer, tryStat(ctx, fs, path)); err != nil {
|
||||
return &NFSStatusError{NFSStatusServerFault, err}
|
||||
}
|
||||
// write the 8 bytes of write verification.
|
||||
if err := xdr.Write(writer, w.Server.ID); err != nil {
|
||||
return &NFSStatusError{NFSStatusServerFault, err}
|
||||
}
|
||||
|
||||
if err := w.Write(writer.Bytes()); err != nil {
|
||||
return &NFSStatusError{NFSStatusServerFault, err}
|
||||
}
|
||||
return nil
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue