Skip to content

Commit

Permalink
open file for write when truncating
Browse files Browse the repository at this point in the history
fix #19
  • Loading branch information
willscott committed Feb 27, 2021
1 parent 70ab9ad commit 3f0761a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion file.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package nfs
import (
"io"
"log"
"math"
"os"
"time"

Expand Down Expand Up @@ -234,10 +235,13 @@ func (s *SetFileAttributes) Apply(changer billy.Change, fs billy.Filesystem, fil
if curr.Mode()&os.ModeSymlink != 0 {
return &NFSStatusError{NFSStatusNotSupp, os.ErrInvalid}
}
fp, err := fs.Open(file)
fp, err := fs.OpenFile(file, os.O_WRONLY|os.O_EXCL, 0)
if err != nil {
return err
}
if *s.SetSize > math.MaxInt64 {
return &NFSStatusError{NFSStatusInval, os.ErrInvalid}
}
if err := fp.Truncate(int64(*s.SetSize)); err != nil {
return err
}
Expand Down

0 comments on commit 3f0761a

Please sign in to comment.