MCPcopy Create free account
hub / github.com/github/gh-aw / RollbackCreatedFiles

Method RollbackCreatedFiles

pkg/cli/file_tracker.go:125–148  ·  view source on GitHub ↗

RollbackCreatedFiles deletes all files that were created during the operation

(verbose bool)

Source from the content-addressed store, hash-verified

123
124// RollbackCreatedFiles deletes all files that were created during the operation
125func (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
151func (ft *FileTracker) RollbackModifiedFiles(verbose bool) error {

Callers 3

RollbackAllFilesMethod · 0.95

Calls 4

LogVerboseFunction · 0.92
PrintMethod · 0.80
PrintfMethod · 0.45
ErrorfMethod · 0.45

Tested by 2