Method: Doing::Util::Backup#select_redo
- Defined in:
- lib/doing/util_backup.rb
#select_redo(filename = nil) ⇒ Object
Select from recent undos. If a filename is provided, only backups of that filename will be used.
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 |
# File 'lib/doing/util_backup.rb', line 117 def select_redo(filename = nil) filename ||= Doing.config.settings['doing_file'] undones = Dir.glob("undone*#{File.basename(filename)}", base: backup_dir).sort raise DoingRuntimeError, 'End of redo history' if undones.empty? total = undones.count = undones.each_with_object([]) do |file, arr| d, _base = date_of_backup(file) next if d.nil? arr.push("#{d.time_ago}\t#{File.join(backup_dir, file)}") end raise DoingRuntimeError, 'No backup files to load' if .empty? backup_file = (, filename) idx = undones.index(File.basename(backup_file)) skipped = undones.slice!(idx, undones.count - idx) undone = skipped.shift redo_file = File.join(backup_dir, undone) FileUtils.move(redo_file, filename) skipped.each do |f| FileUtils.mv(File.join(backup_dir, f), File.join(backup_dir, f.sub(/^undone/, ''))) end Doing.logger.warn('File update:', "restored undo step #{idx}/#{total}") Doing.logger.debug('Backup:', "#{total - skipped.count - 1} redos remaining") end |