diff options
author | elijah <elijah@riseup.net> | 2013-01-13 20:26:30 -0800 |
---|---|---|
committer | elijah <elijah@riseup.net> | 2013-01-13 20:26:30 -0800 |
commit | bea336480bf90f7c24737809e27b0bd224f42233 (patch) | |
tree | 787e52fae2a2653d74145ac9e0fedfa09281f237 | |
parent | 95225c89cef3dbe90e676905f8f3accd9ab314a1 (diff) |
add Util.relative_symlink
-rw-r--r-- | lib/leap_cli/util.rb | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/leap_cli/util.rb b/lib/leap_cli/util.rb index d12c5a6..fb5eb52 100644 --- a/lib/leap_cli/util.rb +++ b/lib/leap_cli/util.rb @@ -1,6 +1,7 @@ require 'digest/md5' require 'paint' require 'fileutils' +require 'pathname' require 'erb' require 'pty' @@ -277,6 +278,24 @@ module LeapCli end # + # creates a relative symlink from absolute paths, removing prior symlink if necessary + # + # symlink 'new' is created, pointing to 'old' + # + def relative_symlink(old, new) + relative_path = Pathname.new(old).relative_path_from(Pathname.new(new)) + if File.symlink?(new) + if File.readlink(new) != relative_path.to_s + File.unlink(new) + log :updated, 'symlink %s' % Path.relative_path(new) + end + else + log :created, 'symlink %s' % Path.relative_path(new) + end + FileUtils.ln_s(relative_path, new) + end + + # # compares md5 fingerprints to see if the contents of a file match the string we have in memory # def file_content_equals?(filepath, contents) |