RollbackCreatedFiles deletes all files that were created during the operation
(verbose bool)
| 123 | |
| 124 | // RollbackCreatedFiles deletes all files that were created during the operation |
| 125 | func (ft *FileTracker) RollbackCreatedFiles(verbose bool) error { |
| 126 | if len(ft.CreatedFiles) == 0 { |
| 127 | return nil |
| 128 | } |
| 129 | |
| 130 | fileTrackerLog.Printf("Rolling back %d created files", len(ft.CreatedFiles)) |
| 131 | console.LogVerbose(verbose, fmt.Sprintf("Rolling back %d created files...", len(ft.CreatedFiles))) |
| 132 | |
| 133 | var errors []string |
| 134 | for _, file := range ft.CreatedFiles { |
| 135 | console.LogVerbose(verbose, " - Deleting "+file) |
| 136 | if err := os.Remove(file); err != nil && !os.IsNotExist(err) { |
| 137 | fileTrackerLog.Printf("Failed to delete %s: %v", file, err) |
| 138 | errors = append(errors, fmt.Sprintf("failed to delete %s: %v", file, err)) |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | if len(errors) > 0 { |
| 143 | return fmt.Errorf("rollback errors: %s", strings.Join(errors, "; ")) |
| 144 | } |
| 145 | |
| 146 | fileTrackerLog.Print("Successfully rolled back created files") |
| 147 | return nil |
| 148 | } |
| 149 | |
| 150 | // RollbackModifiedFiles restores all modified files to their original state |
| 151 | func (ft *FileTracker) RollbackModifiedFiles(verbose bool) error { |