()
| 298 | } |
| 299 | |
| 300 | func (bm *BackupManager) deleteBackup() { |
| 301 | if isPending, pendingOperation := models.GlobalState.IsVMPending(bm.vm); isPending { |
| 302 | bm.app.showMessageSafe(fmt.Sprintf("Cannot delete backup while '%s' is in progress", pendingOperation)) |
| 303 | return |
| 304 | } |
| 305 | |
| 306 | backup := bm.backupTable.GetSelectedBackup() |
| 307 | if backup == nil { |
| 308 | bm.updateInfoText(utils.GetIconLabel("No backup selected.", "❌", bm.app.config.ShowIcons)) |
| 309 | return |
| 310 | } |
| 311 | |
| 312 | // Prevent deleting the "Running" fake backup |
| 313 | if strings.HasPrefix(backup.VolID, "TASK:") { |
| 314 | bm.updateInfoText(utils.GetIconLabel("Cannot delete an in-progress backup task.", "❌", bm.app.config.ShowIcons)) |
| 315 | return |
| 316 | } |
| 317 | |
| 318 | bm.app.lastFocus = bm.app.GetFocus() |
| 319 | |
| 320 | message := fmt.Sprintf("Are you sure you want to delete backup '%s'\n\nThis action cannot be undone.", backup.VolID) |
| 321 | |
| 322 | onConfirm := func() { |
| 323 | bm.app.pages.RemovePage("confirmation") |
| 324 | if bm.app.lastFocus != nil { |
| 325 | bm.app.SetFocus(bm.app.lastFocus) |
| 326 | } |
| 327 | |
| 328 | bm.app.header.ShowLoading(fmt.Sprintf("Deleting backup '%s'", backup.VolID)) |
| 329 | |
| 330 | go func() { |
| 331 | err := bm.operations.DeleteBackup(backup.VolID) |
| 332 | bm.app.Application.QueueUpdateDraw(func() { |
| 333 | if err != nil { |
| 334 | bm.app.header.ShowError(fmt.Sprintf("Failed to delete backup: %v", err)) |
| 335 | } else { |
| 336 | bm.app.header.ShowSuccess(fmt.Sprintf("Successfully deleted backup %s", backup.VolID)) |
| 337 | |
| 338 | // Show refreshing status |
| 339 | bm.updateInfoText("Refreshing list...") |
| 340 | |
| 341 | // Reload backups after delay |
| 342 | go func() { |
| 343 | time.Sleep(1 * time.Second) |
| 344 | // Clear cache to ensure we don't show the deleted backup |
| 345 | bm.app.ClearAPICache() |
| 346 | bm.loadBackups() |
| 347 | }() |
| 348 | } |
| 349 | }) |
| 350 | }() |
| 351 | } |
| 352 | |
| 353 | onCancel := func() { |
| 354 | bm.app.pages.RemovePage("confirmation") |
| 355 | if bm.app.lastFocus != nil { |
| 356 | bm.app.SetFocus(bm.app.lastFocus) |
| 357 | } |
no test coverage detected