Skip to content

Commit

Permalink
Merge pull request #2258 from rolandwalker/hardlink_fonts
Browse files Browse the repository at this point in the history
use hard links for fonts instead of symlinks
  • Loading branch information
phinze committed Jan 10, 2014
2 parents 2412bfe + 4123b05 commit 9135ff5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 8 deletions.
1 change: 1 addition & 0 deletions lib/cask/artifact.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Cask::Artifact; end

require 'cask/artifact/base'
require 'cask/artifact/symlinked'
require 'cask/artifact/hardlinked'

require 'cask/artifact/app'
require 'cask/artifact/binary'
Expand Down
2 changes: 1 addition & 1 deletion lib/cask/artifact/font.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
class Cask::Artifact::Font < Cask::Artifact::Symlinked
class Cask::Artifact::Font < Cask::Artifact::Hardlinked
end
14 changes: 14 additions & 0 deletions lib/cask/artifact/hardlinked.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class Cask::Artifact::Hardlinked < Cask::Artifact::Symlinked
def self.islink?(path)
return false unless path.respond_to?(:stat)
path.stat.nlink > 1
end

def self.link_type_english_name
'Hardlink'
end

def create_filesystem_link(source, target)
@command.run!('/bin/ln', :args => ['-hf', source, target])
end
end
24 changes: 18 additions & 6 deletions lib/cask/artifact/symlinked.rb
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
class Cask::Artifact::Symlinked < Cask::Artifact::Base
def self.islink?(path)
path.symlink?
end

def self.link_type_english_name
'Symlink'
end

def create_filesystem_link(source, target)
@command.run!('/bin/ln', :args => ['-hfs', source, target])
end

def link(artifact_relative_path)
source = @cask.destination_path.join(artifact_relative_path)
target = Cask.send(self.class.artifact_dirmethod).join(source.basename)
return unless preflight_checks(source, target)
ohai "Linking #{self.class.artifact_english_name} '#{source.basename}' to '#{target}'"
@command.run!('/bin/ln', :args => ['-hfs', 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_relative_path)
linked_path = Cask.send(self.class.artifact_dirmethod).join(Pathname(artifact_relative_path).basename)
if linked_path.exist? && linked_path.symlink?
ohai "Removing #{self.class.artifact_english_name} link: '#{linked_path}'"
if linked_path.exist? && self.class.islink?(linked_path)
ohai "Removing #{self.class.artifact_english_name} #{self.class.link_type_english_name.downcase}: '#{linked_path}'"
linked_path.delete
end
end
Expand All @@ -24,12 +36,12 @@ def uninstall
end

def preflight_checks(source, target)
if target.exist? && !target.symlink?
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 "it seems the symlink source is not there: '#{source}'"
raise "it seems the #{self.class.link_type_english_name.downcase} source is not there: '#{source}'"
end
true
end
Expand Down
2 changes: 1 addition & 1 deletion test/cask/artifact/app_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@

TestHelper.must_output(self, lambda {
Cask::Artifact::App.new(cask).install
}, "==> Linking App 'Caffeine.app' to '#{Cask.appdir.join('Caffeine.app')}'")
}, "==> Symlinking App 'Caffeine.app' to '#{Cask.appdir.join('Caffeine.app')}'")

File.readlink(Cask.appdir/'Caffeine.app').wont_equal '/tmp'
end
Expand Down

0 comments on commit 9135ff5

Please sign in to comment.