ApplyBackup applies the corresponding backup file to this buffer (if one exists) Returns true if a backup was applied
(fsize int64)
| 156 | // ApplyBackup applies the corresponding backup file to this buffer (if one exists) |
| 157 | // Returns true if a backup was applied |
| 158 | func (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 | } |
no test coverage detected