diff --git a/lib/cask.rb b/lib/cask.rb index 32b9caa77300..f33396f1f660 100644 --- a/lib/cask.rb +++ b/lib/cask.rb @@ -96,9 +96,10 @@ def self.nowstamp_metadata_path(container_path) end end - attr_reader :token - def initialize(token=self.class.token) - @token = token + attr_reader :token, :sourcefile_path + def initialize(sourcefile_path=nil) + @sourcefile_path = sourcefile_path + @token = self.class.token end def caskroom_path diff --git a/lib/cask/installer.rb b/lib/cask/installer.rb index 8a0de7ee1428..632b03f336a4 100644 --- a/lib/cask/installer.rb +++ b/lib/cask/installer.rb @@ -59,6 +59,7 @@ def install(force=false) download extract_primary_container install_artifacts + save_caskfile force enable_accessibility_access rescue StandardError => e purge_versioned_files @@ -217,6 +218,22 @@ def disable_accessibility_access end end + def save_caskfile(force=false) + timestamp = :now + create = true + savedir = @cask.metadata_subdir('Casks', timestamp, create) + if Dir.entries(savedir).size > 2 + # should not happen + if force + savedir.rmtree + FileUtils.mkdir_p savedir + else + raise CaskAlreadyInstalledError.new(@cask) + end + end + FileUtils.copy(@cask.sourcefile_path, savedir) if @cask.sourcefile_path + end + def uninstall(force=false) odebug "Cask::Installer.uninstall" disable_accessibility_access diff --git a/lib/cask/source/path_base.rb b/lib/cask/source/path_base.rb index ae6d64b3d7e1..be8125271c32 100644 --- a/lib/cask/source/path_base.rb +++ b/lib/cask/source/path_base.rb @@ -78,7 +78,7 @@ def load raise e end begin - Object.const_get(cask_class_name).new + Object.const_get(cask_class_name).new(path) rescue CaskError, StandardError, ScriptError => e # bug: e.message.concat doesn't work with CaskError exceptions e.message.concat(" while instantiating '#{cask_class_name}' from '#{path}'") diff --git a/lib/cask/without_source.rb b/lib/cask/without_source.rb index 03305fe2c816..6655a8a2a3f4 100644 --- a/lib/cask/without_source.rb +++ b/lib/cask/without_source.rb @@ -3,6 +3,11 @@ def staged_path caskroom_path.children.first end + def initialize(sourcefile_path=nil) + @sourcefile_path = sourcefile_path + @token = sourcefile_path + end + def to_s "#{token} (!)" end