@@ -54,6 +54,7 @@ func ensureRecovery(filename string) (err error) {
5454 if err = backupRestore (filename ); err != nil {
5555 return err
5656 }
57+ _ = backupRemove (filename )
5758 } else {
5859 // We do not see a backup.
5960 // Do we have a final destination then?
@@ -101,6 +102,10 @@ func backupRestore(path string) error {
101102 return err
102103}
103104
105+ func backupRemove (path string ) error {
106+ return os .Remove (backupLocation (path ))
107+ }
108+
104109// backupExists checks if a backup file exists for file located at `path`.
105110func backupExists (path string ) (bool , error ) {
106111 _ , err := os .Stat (backupLocation (path ))
@@ -190,16 +195,16 @@ func internalCopy(sourcePath, destinationPath string) (err error) {
190195 return err
191196 }
192197
198+ defer func () {
199+ err = errors .Join (err , source .Close ())
200+ }()
201+
193202 // Read file length
194203 srcInfo , err := source .Stat ()
195204 if err != nil {
196205 return err
197206 }
198207
199- defer func () {
200- err = errors .Join (err , source .Close ())
201- }()
202-
203208 return fileWrite (source , srcInfo .Size (), destinationPath , privateFilePermission , srcInfo .ModTime ())
204209}
205210
@@ -220,11 +225,6 @@ func fileWrite(source io.Reader, size int64, destinationPath string, perm os.Fil
220225 if mustClose {
221226 err = errors .Join (err , destination .Close ())
222227 }
223-
224- // Remove destination if we failed anywhere. Ignore removal failures.
225- if err != nil {
226- _ = os .Remove (destinationPath )
227- }
228228 }()
229229
230230 // Copy over
0 commit comments