class VimRecovery::Swapfile

Constants

B0_DIRTY
B0_FF_MASK
B0_HAS_FENC
B0_MAGIC_CHAR
B0_MAGIC_INT
B0_MAGIC_LONG

github.com/vim/vim/blob/95f096030ed1a8afea028f2ea295d6f6a70f466f/src/memline.c#L143

B0_MAGIC_SHORT
B0_SAME_DIR
Block0
EOL
EOL_DOS
EOL_MAC
EOL_UNIX

github.com/vim/vim/blob/95f096030ed1a8afea028f2ea295d6f6a70f466f/src/option.h#L80

HEADER_FORMAT

github.com/vim/vim/blob/95f096030ed1a8afea028f2ea295d6f6a70f466f/src/memline.c#L160

VALID_BLOCK_IDS

github.com/vim/vim/blob/95f096030ed1a8afea028f2ea295d6f6a70f466f/src/memline.c#L62

Public Class Methods

swapfile?(name) click to toggle source
# File lib/vim_recovery/swapfile.rb, line 51
def self.swapfile?(name)
  open(name) { |f| f.valid_block0? }
end

Public Instance Methods

encrypted?() click to toggle source
# File lib/vim_recovery/swapfile.rb, line 55
def encrypted?
  # "b0" not encrypted
  # "bc" encrypted (zip)
  # "bC" encrypted (blowfish)
  # "bd" encrypted (blowfish2)
  block0.id[1] != '0'
end
file_format() click to toggle source
# File lib/vim_recovery/swapfile.rb, line 103
def file_format
  # "Zero means it's not set (compatible with Vim 6.x), otherwise it's
  # EOL_UNIX + 1, EOL_DOS + 1 or EOL_MAC + 1."
  EOL[(block0.flags & B0_FF_MASK) - 1]
end
has_file_encoding?() click to toggle source
# File lib/vim_recovery/swapfile.rb, line 99
def has_file_encoding?
  B0_HAS_FENC & block0.flags > 0
end
modified?() click to toggle source
# File lib/vim_recovery/swapfile.rb, line 63
def modified?
  block0.dirty == B0_DIRTY
end
mtime() click to toggle source
Calls superclass method
# File lib/vim_recovery/swapfile.rb, line 67
def mtime
  block0.mtime == 0 ? super : Time.at(block0.mtime)
end
original_filename() click to toggle source
# File lib/vim_recovery/swapfile.rb, line 75
def original_filename
  block0.fname unless block0.fname.empty?
end
pid() click to toggle source
# File lib/vim_recovery/swapfile.rb, line 71
def pid
  block0.pid
end
same_dir?() click to toggle source

Swap file is in directory of edited file (see “:help directory”).

# File lib/vim_recovery/swapfile.rb, line 95
def same_dir?
  B0_SAME_DIR & block0.flags > 0
end
still_running?() click to toggle source
# File lib/vim_recovery/swapfile.rb, line 79
def still_running?
  Process.getpgid pid
  true
rescue Errno::ESRCH
  false
end
valid_block0?() click to toggle source
# File lib/vim_recovery/swapfile.rb, line 109
def valid_block0?
  rewind
  VALID_BLOCK_IDS.include?(read 2)
end

Private Instance Methods

block0() click to toggle source
# File lib/vim_recovery/swapfile.rb, line 116
def block0
  @block0 ||=
    begin
      rewind
      Block0.new *read(1032).unpack(HEADER_FORMAT)
    end
end