save: Further rework of overwriteFile()

- extract the open logic into `openFile()` and return a `wrappedFile`
- extract the closing logic into `Close()` and make a method of `wrappedFile`
- rename `writeFile()` into `Write()` and make a method of `wrappedFile`

This allows to use the split parts alone while keeping overwriteFile() as simple
interface to use all in a row.
This commit is contained in:
Jöran Karl
2024-11-19 23:12:26 +01:00
parent f8d98558f0
commit 9592bb1549
2 changed files with 115 additions and 71 deletions

View File

@@ -88,7 +88,7 @@ func (b *Buffer) Backup() error {
name := util.DetermineEscapePath(backupdir, b.AbsPath)
if _, err := os.Stat(name); errors.Is(err, fs.ErrNotExist) {
_, err = b.overwriteFile(name, false)
_, err = b.overwriteFile(name)
if err == nil {
b.requestedBackup = false
}
@@ -96,7 +96,7 @@ func (b *Buffer) Backup() error {
}
tmp := util.AppendBackupSuffix(name)
_, err := b.overwriteFile(tmp, false)
_, err := b.overwriteFile(tmp)
if err != nil {
os.Remove(tmp)
return err