mem.File.Truncate should use lock

Fixes: #272
This commit is contained in:
Rafal Zajac 2020-11-13 22:59:22 +01:00
parent 6c0630556d
commit d175ebcca8
1 changed files with 2 additions and 0 deletions

View File

@ -210,6 +210,8 @@ func (f *File) Truncate(size int64) error {
if size < 0 { if size < 0 {
return ErrOutOfRange return ErrOutOfRange
} }
f.fileData.Lock()
defer f.fileData.Unlock()
if size > int64(len(f.fileData.data)) { if size > int64(len(f.fileData.data)) {
diff := 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))...) f.fileData.data = append(f.fileData.data, bytes.Repeat([]byte{00}, int(diff))...)