Refactor the ln_s method to decrease its cyclomatic complexity
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user