@@ -54,6 +54,7 @@ func ensureRecovery(filename string) (err error) {
54
54
if err = backupRestore (filename ); err != nil {
55
55
return err
56
56
}
57
+ _ = backupRemove (filename )
57
58
} else {
58
59
// We do not see a backup.
59
60
// Do we have a final destination then?
@@ -101,6 +102,10 @@ func backupRestore(path string) error {
101
102
return err
102
103
}
103
104
105
+ func backupRemove (path string ) error {
106
+ return os .Remove (backupLocation (path ))
107
+ }
108
+
104
109
// backupExists checks if a backup file exists for file located at `path`.
105
110
func backupExists (path string ) (bool , error ) {
106
111
_ , err := os .Stat (backupLocation (path ))
@@ -190,16 +195,16 @@ func internalCopy(sourcePath, destinationPath string) (err error) {
190
195
return err
191
196
}
192
197
198
+ defer func () {
199
+ err = errors .Join (err , source .Close ())
200
+ }()
201
+
193
202
// Read file length
194
203
srcInfo , err := source .Stat ()
195
204
if err != nil {
196
205
return err
197
206
}
198
207
199
- defer func () {
200
- err = errors .Join (err , source .Close ())
201
- }()
202
-
203
208
return fileWrite (source , srcInfo .Size (), destinationPath , privateFilePermission , srcInfo .ModTime ())
204
209
}
205
210
@@ -220,11 +225,6 @@ func fileWrite(source io.Reader, size int64, destinationPath string, perm os.Fil
220
225
if mustClose {
221
226
err = errors .Join (err , destination .Close ())
222
227
}
223
-
224
- // Remove destination if we failed anywhere. Ignore removal failures.
225
- if err != nil {
226
- _ = os .Remove (destinationPath )
227
- }
228
228
}()
229
229
230
230
// Copy over
0 commit comments