Merge pull request #273 from rzajac/mem-file-truncate-use-lock

mem.File.Truncate should use lock
This commit is contained in:
Michail Kargakis 2020-11-15 14:23:41 +01:00 committed by GitHub
commit 736b98e92c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 {
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))...)