Skip to content

Commit

Permalink
Store metadata with installed Casks.
Browse files Browse the repository at this point in the history
Step 2: Snapshot the Cask file used at install-time, using
the previously-merged metadata directory support.

Using a simple filesystem-is-a-database approach, we set up a
`.metadata` directory for each installed Cask in which we can
record any information, starting with a copy of the Cask
definition which was used at install-time.

This should be useful for various cases such as:
- a fallback when the Cask was renamed/removed.  We
  currently cannot recover any uninstall info in that
  scenario
- installation of multiple versions of the same software

There might be a smarter way to discover the source filename
for the Cask through introspection or some deep Ruby voodoo.
All I could come up with was to pass the filename in on the
constructor, which seems perfectly reasonable if voodoo is
not available.  The existing code was taking the title as an
argument to the constructor, which is dispensable.

This PR contains no code to actually make use of the metadata,
but only takes care of the relevant book-keeping: creation,
destruction, as well as organization of metadata according to
software version number and timestamp.
  • Loading branch information
rolandwalker committed Dec 10, 2014
1 parent 8cd3946 commit bf99c6b
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
7 changes: 4 additions & 3 deletions lib/cask.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions lib/cask/installer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/cask/source/path_base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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}'")
Expand Down
5 changes: 5 additions & 0 deletions lib/cask/without_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bf99c6b

Please sign in to comment.