Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use hard links for fonts instead of symlinks #2258

Merged
merged 1 commit into from
Jan 10, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/block'
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