blob: 01e98ac35341233857e0735aae3dad57b7a42cd3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  | 
require "hbc/artifact/relocated"
module Hbc
  module Artifact
    class Moved < Relocated
      def self.english_description
        "#{artifact_english_name}s"
      end
      def install_phase
        each_artifact(&method(:move))
      end
      def uninstall_phase
        each_artifact(&method(:delete))
      end
      private
      def move
        if Utils.path_occupied?(target)
          message = "It seems there is already #{self.class.artifact_english_article} #{self.class.artifact_english_name} at '#{target}'"
          raise CaskError, "#{message}." unless force
          opoo "#{message}; overwriting."
          delete
        end
        unless source.exist?
          raise CaskError, "It seems the #{self.class.artifact_english_name} source '#{source}' is not there."
        end
        ohai "Moving #{self.class.artifact_english_name} '#{source.basename}' to '#{target}'."
        target.dirname.mkpath
        FileUtils.move(source, target)
        add_altname_metadata target, source.basename.to_s
      end
      def delete
        ohai "Removing #{self.class.artifact_english_name} '#{target}'."
        return unless Utils.path_occupied?(target)
        raise CaskError, "Cannot remove undeletable #{self.class.artifact_english_name}." if MacOS.undeletable?(target)
        if force
          Utils.gain_permissions_remove(target, command: @command)
        else
          target.rmtree
        end
      end
      def summarize_artifact(artifact_spec)
        load_specification artifact_spec
        if target.exist?
          "#{printable_target} (#{target.abv})"
        else
          Formatter.error(printable_target, label: "Missing #{self.class.artifact_english_name}")
        end
      end
    end
  end
end
  |