diff --git a/.rubocop.yml b/.rubocop.yml index b973d36..1b7634b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -10,7 +10,7 @@ ClassLength: Enabled: false CyclomaticComplexity: - Max: 9 + Max: 7 LineLength: Max: 163 diff --git a/lib/homesick.rb b/lib/homesick.rb index dde5198..628ef24 100644 --- a/lib/homesick.rb +++ b/lib/homesick.rb @@ -387,6 +387,10 @@ class Homesick < Thor first_p.mtime > second_p.mtime && !first_p.symlink? end + def collision_accepted? + options[:force] || shell.file_collision(destination) { source } + end + def each_file(castle, basedir, subdirs) absolute_basedir = Pathname.new(basedir).expand_path inside basedir do diff --git a/lib/homesick/actions.rb b/lib/homesick/actions.rb index 096aad4..3bfd4e2 100644 --- a/lib/homesick/actions.rb +++ b/lib/homesick/actions.rb @@ -148,18 +148,16 @@ class Homesick destination = Pathname.new(destination) FileUtils.mkdir_p destination.dirname - if destination.symlink? - if destination.readlink == source - say_status :identical, destination.expand_path, :blue unless options[:quiet] - else - say_status :conflict, "#{destination} exists and points to #{destination.readlink}", :red unless options[:quiet] + if destination.symlink? && destination.readlink == source + say_status :identical, destination.expand_path, :blue unless options[:quiet] + elsif destination.symlink? + say_status :conflict, "#{destination} exists and points to #{destination.readlink}", :red unless options[:quiet] - system "ln -nsf '#{source}' '#{destination}'" if (options[:force] || shell.file_collision(destination) { source }) && !options[:pretend] - end + smart_system "ln -nsf '#{source}' '#{destination}'" if collision_accepted? elsif destination.exist? say_status :conflict, "#{destination} exists", :red unless options[:quiet] - if options[:force] || shell.file_collision(destination) { source } + if collision_accepted? system "rm -rf '#{destination}'" unless options[:pretend] system "ln -sf '#{source}' '#{destination}'" unless options[:pretend] end