Class: HFAM::Command::Symlink

Inherits:
Base
  • Object
show all
Defined in:
lib/hfam/commands/symlink.rb

Instance Method Summary collapse

Instance Method Details

#run(command) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/hfam/commands/symlink.rb', line 7

def run(command)
  src  = command[1]

  ::HFAM::Logger.error("No such file or directory: #{src}") and return unless File.exist? src

  # preprend the dest file with a '.' if the src file is not a hidden file 
  file = src.split('/').last
  file = ::FileUtils.hidden_file?(file) ? file : ".#{file}"
  dest = "#{command[2]}/#{file}"

  # ln -s with --force option
  ::FileUtils.ln_sf(src, dest)

  ::HFAM::Logger.success("Symlink: ln -s #{src} #{dest}")

rescue ::Errno::EACCES => e
  l::HFAM::Logger.error("Unable to generate symlink #{src} #{dest} (Permission Denied)")
end