[#970] fstree: Move temporary path handling in a separate function

Allow to easier test different implementations.

Signed-off-by: Evgenii Stratonikov <e.stratonikov@yadro.com>
This commit is contained in:
Evgenii Stratonikov 2024-02-01 10:26:29 +03:00 committed by Evgenii Stratonikov
parent d19ade23c8
commit 9a622a750d

View file

@ -357,9 +357,12 @@ func (t *FSTree) Put(ctx context.Context, prm common.PutPrm) (common.PutRes, err
} }
size = len(prm.RawData) size = len(prm.RawData)
return common.PutRes{StorageID: []byte{}}, t.writeData(p, prm.RawData)
}
func (t *FSTree) writeData(p string, data []byte) error {
tmpPath := p + "#" + strconv.FormatUint(t.suffix.Add(1), 10) tmpPath := p + "#" + strconv.FormatUint(t.suffix.Add(1), 10)
err = t.writeAndRename(tmpPath, p, prm.RawData) return t.writeAndRename(tmpPath, p, data)
return common.PutRes{StorageID: []byte{}}, err
} }
// writeAndRename opens tmpPath exclusively, writes data to it and renames it to p. // writeAndRename opens tmpPath exclusively, writes data to it and renames it to p.