diff --git a/lib/hbc/artifact/font.rb b/lib/hbc/artifact/font.rb index cb9e63087acd..9697d9e13803 100644 --- a/lib/hbc/artifact/font.rb +++ b/lib/hbc/artifact/font.rb @@ -1,4 +1,4 @@ -require "hbc/artifact/hardlinked" +require "hbc/artifact/moved" -class Hbc::Artifact::Font < Hbc::Artifact::Hardlinked +class Hbc::Artifact::Font < Hbc::Artifact::Moved end diff --git a/lib/hbc/artifact/hardlinked.rb b/lib/hbc/artifact/hardlinked.rb deleted file mode 100644 index c1ea4a6b007e..000000000000 --- a/lib/hbc/artifact/hardlinked.rb +++ /dev/null @@ -1,24 +0,0 @@ -require "hbc/artifact/linked" - -class Hbc::Artifact::Hardlinked < Hbc::Artifact::Linked - def self.link_type_english_name - "Hardlink" - end - - def self.islink?(path) - return false unless path.respond_to?(:stat) - path.stat.nlink > 1 - end - - def create_filesystem_link(source, target) - Pathname.new(target).dirname.mkpath - @command.run!("/bin/ln", args: ["-hf", "--", source, target]) - add_altname_metadata source, target.basename.to_s - end - - def summarize_one_link(artifact_spec) - load_specification artifact_spec - return unless self.class.islink?(target) - "'#{target}'".sub(%r{^'#{ENV['HOME']}/*}, "~/'") - end -end diff --git a/lib/hbc/artifact/linked.rb b/lib/hbc/artifact/linked.rb deleted file mode 100644 index e54ac10d9d3b..000000000000 --- a/lib/hbc/artifact/linked.rb +++ /dev/null @@ -1,43 +0,0 @@ -require "hbc/artifact/relocated" - -class Hbc::Artifact::Linked < Hbc::Artifact::Relocated - def summary - { - english_description: "#{self.class.artifact_english_name} #{self.class.link_type_english_name}s managed by brew-cask:", - contents: @cask.artifacts[self.class.artifact_dsl_key].map(&method(:summarize_one_link)) - [nil], - } - end - - def link(artifact_spec) - load_specification artifact_spec - return unless preflight_checks(source, target) - ohai "#{self.class.link_type_english_name}ing #{self.class.artifact_english_name} '#{source.basename}' to '#{target}'" - create_filesystem_link(source, target) - end - - def unlink(artifact_spec) - load_specification artifact_spec - return unless self.class.islink?(target) - ohai "Removing #{self.class.artifact_english_name} #{self.class.link_type_english_name.downcase}: '#{target}'" - target.delete - end - - def install_phase - @cask.artifacts[self.class.artifact_dsl_key].each { |artifact| link(artifact) } - end - - def uninstall_phase - @cask.artifacts[self.class.artifact_dsl_key].each { |artifact| unlink(artifact) } - end - - def preflight_checks(source, target) - if target.exist? && !self.class.islink?(target) - ohai "It seems there is already #{self.class.artifact_english_article} #{self.class.artifact_english_name} at '#{target}'; not linking." - return false - end - unless source.exist? - raise Hbc::CaskError, "It seems the #{self.class.link_type_english_name.downcase} source is not there: '#{source}'" - end - true - end -end diff --git a/lib/hbc/artifact/symlinked.rb b/lib/hbc/artifact/symlinked.rb index 2bf5de4a594f..d72bd63b3707 100644 --- a/lib/hbc/artifact/symlinked.rb +++ b/lib/hbc/artifact/symlinked.rb @@ -1,6 +1,6 @@ -require "hbc/artifact/linked" +require "hbc/artifact/relocated" -class Hbc::Artifact::Symlinked < Hbc::Artifact::Linked +class Hbc::Artifact::Symlinked < Hbc::Artifact::Relocated def self.islink?(path) path.symlink? end @@ -9,6 +9,46 @@ def self.link_type_english_name "Symlink" end + def summary + { + english_description: "#{self.class.artifact_english_name} #{self.class.link_type_english_name}s managed by brew-cask:", + contents: @cask.artifacts[self.class.artifact_dsl_key].map(&method(:summarize_one_link)) - [nil], + } + end + + def link(artifact_spec) + load_specification artifact_spec + return unless preflight_checks(source, target) + ohai "#{self.class.link_type_english_name}ing #{self.class.artifact_english_name} '#{source.basename}' to '#{target}'" + create_filesystem_link(source, target) + end + + def unlink(artifact_spec) + load_specification artifact_spec + return unless self.class.islink?(target) + ohai "Removing #{self.class.artifact_english_name} #{self.class.link_type_english_name.downcase}: '#{target}'" + target.delete + end + + def install_phase + @cask.artifacts[self.class.artifact_dsl_key].each { |artifact| link(artifact) } + end + + def uninstall_phase + @cask.artifacts[self.class.artifact_dsl_key].each { |artifact| unlink(artifact) } + end + + def preflight_checks(source, target) + if target.exist? && !self.class.islink?(target) + ohai "It seems there is already #{self.class.artifact_english_article} #{self.class.artifact_english_name} at '#{target}'; not linking." + return false + end + unless source.exist? + raise Hbc::CaskError, "It seems the #{self.class.link_type_english_name.downcase} source is not there: '#{source}'" + end + true + end + def create_filesystem_link(source, target) Pathname.new(target).dirname.mkpath @command.run!("/bin/ln", args: ["-hfs", "--", source, target])