mirror of https://github.com/spf13/afero.git
Merge pull request #273 from rzajac/mem-file-truncate-use-lock
mem.File.Truncate should use lock
This commit is contained in:
commit
736b98e92c
|
@ -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))...)
|
||||
|
|
Loading…
Reference in New Issue