Skip to content

Commit

Permalink
Move fonts instead of hardlinking them (Homebrew#23728)
Browse files Browse the repository at this point in the history
  • Loading branch information
jawshooah authored and Jonathan Dahan committed Sep 24, 2016
1 parent 376a26a commit 58bc027
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 71 deletions.
4 changes: 2 additions & 2 deletions lib/hbc/artifact/font.rb
Original file line number Diff line number Diff line change
@@ -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
24 changes: 0 additions & 24 deletions lib/hbc/artifact/hardlinked.rb

This file was deleted.

43 changes: 0 additions & 43 deletions lib/hbc/artifact/linked.rb

This file was deleted.

44 changes: 42 additions & 2 deletions lib/hbc/artifact/symlinked.rb
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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])
Expand Down

0 comments on commit 58bc027

Please sign in to comment.