@@ -91,18 +91,21 @@ func (res *IndexResource) Download(destDir *paths.Path, downloadCB DownloadProgr
91
91
// Make a backup copy of old index and signature so the defer function can rollback in case of errors.
92
92
indexPath := destDir .Join (indexFileName )
93
93
oldIndex := tmp .Join ("old_index" )
94
- if err := indexPath .CopyTo (oldIndex ); err != nil {
95
- return & arduino.PermissionDeniedError {Message : tr ("Error saving downloaded index %s" , res .URL ), Cause : err }
94
+ if indexPath .Exist () {
95
+ if err := indexPath .CopyTo (oldIndex ); err != nil {
96
+ return & arduino.PermissionDeniedError {Message : tr ("Error saving downloaded index" ), Cause : err }
97
+ }
98
+ defer oldIndex .CopyTo (indexPath ) // will silently fail in case of success
96
99
}
97
- defer oldIndex .CopyTo (indexPath ) // will silently fail in case of success
98
100
oldSignature := tmp .Join ("old_signature" )
99
- if err := signaturePath .CopyTo (oldSignature ); err != nil {
100
- return & arduino.PermissionDeniedError {Message : tr ("Error saving downloaded index %s" , res .URL ), Cause : err }
101
+ if oldSignature .Exist () {
102
+ if err := signaturePath .CopyTo (oldSignature ); err != nil {
103
+ return & arduino.PermissionDeniedError {Message : tr ("Error saving downloaded index signature" ), Cause : err }
104
+ }
105
+ defer oldSignature .CopyTo (signaturePath ) // will silently fail in case of success
101
106
}
102
- defer oldSignature .CopyTo (signaturePath ) // will silently fail in case of success
103
-
104
107
if err := tmpIndexPath .CopyTo (indexPath ); err != nil {
105
- return & arduino.PermissionDeniedError {Message : tr ("Error saving downloaded index %s" , res . URL ), Cause : err }
108
+ return & arduino.PermissionDeniedError {Message : tr ("Error saving downloaded index" ), Cause : err }
106
109
}
107
110
if res .SignatureURL != nil {
108
111
if err := tmpSignaturePath .CopyTo (signaturePath ); err != nil {
0 commit comments