Skip to content

Commit

Permalink
mem.File.Truncate should use lock
Browse files Browse the repository at this point in the history
Fixes: #272
  • Loading branch information
rzajac committed Nov 13, 2020
1 parent 6c06305 commit d175ebc
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions mem/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,8 @@ func (f *File) Truncate(size int64) error {
if size < 0 {
return ErrOutOfRange
}
f.fileData.Lock()
defer f.fileData.Unlock()
if size > int64(len(f.fileData.data)) {
diff := size - int64(len(f.fileData.data))
f.fileData.data = append(f.fileData.data, bytes.Repeat([]byte{00}, int(diff))...)
Expand Down

0 comments on commit d175ebc

Please sign in to comment.