/usr/lib/ruby/vendor_ruby/vim/addon_manager/addon/legacy.rb is in vim-addon-manager 0.5.5.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 | # vim-addons: command line manager of Vim addons
#
# Copyright (C) 2007 Stefano Zacchiroli
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
module Vim
class AddonManager
class Addon
class Legacy < Addon
def initialize(yaml, basedir)
@files = Set.new yaml['files']
raise ArgumentError.new('empty addon') if @files.size == 0
super
end
attr_reader :files
def status(target_dir)
expected_dest = @files.collect {|f| File.join(target_dir, f)}
installed = expected_dest.select do |f|
File.exist? f
end
expected_src = @files.collect {|f| File.join(@basedir, f)}
available = expected_src.select do |f|
File.exist? f
end
status =
if available.size != expected_src.size
missing = expected_src - available
AddonStatus.new(:unavailable, missing)
elsif installed.size == expected_dest.size
AddonStatus.new :installed
elsif installed.size == 0
AddonStatus.new :not_installed
else
missing = expected_dest - installed
prefix = /^#{Regexp.escape target_dir}\/+/o
missing.collect! {|f| f.gsub(prefix, '')}
AddonStatus.new(:broken, missing)
end
status.disabled = is_disabled_in? target_dir
status
end
def install(target_dir)
installed_files = []
symlink = lambda do |file|
dest = File.join(target_dir, file)
self.mkdir(dest)
FileUtils.ln_sf(File.join(basedir, file), dest)
end
status = self.status(target_dir)
case status.status
when :broken
logger.info "installing broken addon '#{self}' to #{target_dir}"
status.missing_files.each(&symlink)
installed_files.concat(status.missing_files.to_a)
when :not_installed
logger.info "installing removed addon '#{self}' to #{target_dir}"
self.files.each(&symlink)
installed_files.concat(self.files.to_a)
when :unavailable
s = "ignoring '#{self}' which is missing source files"
s << "\n- #{status.missing_files.join "\n- "}" if logger.verbose?
logger.warn s
else
logger.info "ignoring '#{self}' which is neither removed nor broken"
end
installed_files
end
def remove(target_dir)
removed_files = []
status = self.status(target_dir)
case status.status
when :installed
logger.info "removing installed addon '#{self}' from #{target_dir}"
self.files.each { |f| rmdirs(target_dir, f) }
removed_files.concat(self.files.to_a)
when :broken
logger.info "removing broken addon '#{self}' from #{target_dir}"
files = (self.files - status.missing_files)
files.each { |f| rmdirs(target_dir, f) }
removed_files.concat(files.to_a)
else
logger.info "ignoring '#{self}' which is neither installed nor broken"
end
removed_files
end
private
def rmdirs(target_dir, file)
File.delete(File.join(target_dir, file))
dir = File.dirname(file)
paths = (dir.include? File::Separator) ? File.split(dir) : [dir]
while paths.size > 0
begin
FileUtils.rmdir(File.join(target_dir, paths))
rescue Errno::ENOTEMPTY
break
end
paths.pop
end
end
end
end
end
end
|