Class: AutomateIt::ShellManager::BaseLink
- Inherits:
-
BaseDriver
- Object
- Common
- Plugin::Base
- Plugin::Driver
- BaseDriver
- AutomateIt::ShellManager::BaseLink
- Defined in:
- lib/automateit/shell_manager/base_link.rb
Overview
ShellManager::BaseLink
An abstract ShellManager driver used by drivers that provide either hard or symbolic links.
Constant Summary
Constants inherited from Plugin::Driver
Plugin::Driver::BASE_DRIVER_NAME
Constants included from Constants
Constants::HELPERS_DIR, Constants::INSTALL_DIR, Constants::PERROR, Constants::PEXEC, Constants::PNOTE, Constants::WARNING_BOILERPLATE
Instance Attribute Summary
Attributes inherited from Plugin::Driver
Attributes inherited from Common
Instance Method Summary collapse
-
#_ln(sources, target, opts = {}) ⇒ Object
See ShellManager#ln.
Methods inherited from BaseDriver
Methods inherited from Plugin::Driver
abstract_driver, #available?, base_driver, base_driver?, depends_on, inherited, manager_token, #setup, #suitability
Methods inherited from Plugin::Base
Methods inherited from Common
#initialize, #log, #nitpick, #noop, #noop=, #noop?, #preview, #preview=, #preview?, #preview_for, #setup, #superuser?, #writing, #writing=, #writing?
Constructor Details
This class inherits a constructor from AutomateIt::Common
Instance Method Details
#_ln(sources, target, opts = {}) ⇒ Object
See ShellManager#ln
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 |
# File 'lib/automateit/shell_manager/base_link.rb', line 9 def _ln(sources, target, opts={}) kind = \ if opts[:symbolic] and opts[:force] :ln_sf elsif opts[:symbolic] :ln_s else :ln end missing = [] sources = [sources].flatten if kind == :ln raise TypeError.new("source for hard link must be a String") unless sources.size == 1 end for source in sources peer = peer_for(source, target) begin peer_stat = File.stat(peer) source_stat = File.stat(source) if peer_stat.ino == source_stat.ino next elsif kind == :ln missing << source elsif Pathname.new(peer).realpath != Pathname.new(source).realpath # It's either :ln_s or :ln_sf missing << source end rescue Errno::ENOENT # File doesn't exist, so obviously missing missing << source end end return false if missing.empty? log.debug(PNOTE+"_ln(%s, %s, %s) # => %s" % [kind, sources.inspect, target.inspect, missing.inspect]) missing = missing.first if missing.size == 1 displayed = "ln" if opts[:symbolic] and opts[:force] displayed << " -sf" else displayed << " -s" if opts[:symbolic] displayed << " -f" if opts[:force] end if kind == :ln log.info(PEXEC+"#{displayed} #{missing} #{target}") FileUtils.ln(missing, target, _fileutils_opts) && missing else log.info(PEXEC+"#{displayed} #{String === missing ? missing : missing.join(' ')} #{target}") FileUtils.send(kind, missing, target, _fileutils_opts) && missing end return missing end |