Skip to content

Commit

Permalink
fstree: rename file after write
Browse files Browse the repository at this point in the history
Signed-off-by: Evgenii Stratonikov <[email protected]>
  • Loading branch information
fyrchik committed Jan 23, 2023
1 parent 773d72c commit 604bbe3
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions pkg/local_object_storage/blobstor/fstree/fstree.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,16 +239,17 @@ func (t *FSTree) Put(prm common.PutPrm) (common.PutRes, error) {
prm.RawData = t.Compress(prm.RawData)
}

err := t.writeFile(p, prm.RawData)
tmpPath := p + "#"
err := t.writeFile(tmpPath, prm.RawData)
if err != nil {
var pe *fs.PathError
if errors.As(err, &pe) && pe.Err == syscall.ENOSPC {
err = common.ErrNoSpace
_ = os.RemoveAll(p)
_ = os.RemoveAll(tmpPath)
}
}

return common.PutRes{StorageID: []byte{}}, err
return common.PutRes{StorageID: []byte{}}, os.Rename(tmpPath, p)
}

func (t *FSTree) writeFlags() int {
Expand Down

0 comments on commit 604bbe3

Please sign in to comment.