MCPcopy
hub / github.com/micro-editor/micro / ApplyBackup

Method ApplyBackup

internal/buffer/backup.go:158–185  ·  view source on GitHub ↗

ApplyBackup applies the corresponding backup file to this buffer (if one exists) Returns true if a backup was applied

(fsize int64)

Source from the content-addressed store, hash-verified

156// ApplyBackup applies the corresponding backup file to this buffer (if one exists)
157// Returns true if a backup was applied
158func (b *SharedBuffer) ApplyBackup(fsize int64) (bool, bool) {
159 if b.Settings["backup"].(bool) && !b.Settings["permbackup"].(bool) && len(b.Path) > 0 && b.Type == BTDefault {
160 backupfile, resolveName := util.DetermineEscapePath(b.backupDir(), b.AbsPath)
161 if info, err := os.Stat(backupfile); err == nil {
162 backup, err := os.Open(backupfile)
163 if err == nil {
164 defer backup.Close()
165 t := info.ModTime()
166 msg := fmt.Sprintf(BackupMsg, b.Path, t.Format("Mon Jan _2 at 15:04, 2006"), backupfile)
167 choice := screen.TermPrompt(msg, []string{"r", "i", "a", "recover", "ignore", "abort"}, true)
168
169 if choice%3 == 0 {
170 // recover
171 b.LineArray = NewLineArray(uint64(fsize), FFAuto, backup)
172 b.setModified()
173 return true, true
174 } else if choice%3 == 1 {
175 // delete
176 b.removeBackup(backupfile, resolveName)
177 } else if choice%3 == 2 {
178 return false, false
179 }
180 }
181 }
182 }
183
184 return false, true
185}

Callers 1

NewBufferFunction · 0.80

Calls 7

backupDirMethod · 0.95
setModifiedMethod · 0.95
removeBackupMethod · 0.95
DetermineEscapePathFunction · 0.92
TermPromptFunction · 0.92
NewLineArrayFunction · 0.85
CloseMethod · 0.65

Tested by

no test coverage detected