diff --git a/Library/Homebrew/cask/lib/hbc/cask.rb b/Library/Homebrew/cask/lib/hbc/cask.rb index 52dd676b4e..975d69d074 100644 --- a/Library/Homebrew/cask/lib/hbc/cask.rb +++ b/Library/Homebrew/cask/lib/hbc/cask.rb @@ -32,7 +32,6 @@ module Hbc end def metadata_path(timestamp = :latest, create = false) - return nil unless metadata_versioned_container_path.respond_to?(:join) if create && timestamp == :latest raise CaskError, "Cannot create metadata path when timestamp is :latest" end diff --git a/Library/Homebrew/cask/lib/hbc/installer.rb b/Library/Homebrew/cask/lib/hbc/installer.rb index b86f3264d2..94d2709462 100644 --- a/Library/Homebrew/cask/lib/hbc/installer.rb +++ b/Library/Homebrew/cask/lib/hbc/installer.rb @@ -295,16 +295,15 @@ module Hbc end def save_caskfile - timestamp = :now - create = true - savedir = @cask.metadata_subdir("Casks", timestamp, create) - if Dir.entries(savedir).size > 2 - # should not happen - raise CaskAlreadyInstalledError, @cask unless force - savedir.rmtree - FileUtils.mkdir_p savedir + unless (old_savedirs = Pathname.glob(@cask.metadata_path("*"))).empty? + old_savedirs.each(&:rmtree) end - FileUtils.copy(@cask.sourcefile_path, savedir) if @cask.sourcefile_path + + return unless @cask.sourcefile_path + + savedir = @cask.metadata_subdir("Casks", :now, true) + savedir.mkpath + FileUtils.copy @cask.sourcefile_path, savedir end def uninstall