lace 0.5.3 → 0.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/bin/lace +31 -44
- data/lib/cmd/activate.rb +4 -2
- data/lib/cmd/apply.rb +33 -11
- data/lib/cmd/deactivate.rb +4 -2
- data/lib/cmd/diff.rb +10 -7
- data/lib/cmd/fetch.rb +6 -11
- data/lib/cmd/help.rb +31 -23
- data/lib/cmd/inspect.rb +42 -17
- data/lib/cmd/list.rb +33 -10
- data/lib/cmd/remove.rb +4 -2
- data/lib/cmd/setup.rb +10 -2
- data/lib/cmd/update.rb +4 -1
- data/lib/cmd/upgrade.rb +10 -7
- data/lib/cmd/validate.rb +55 -65
- data/lib/cmd/where.rb +5 -8
- data/lib/extend/ARGV.rb +24 -32
- data/lib/extend/pathname.rb +29 -33
- data/lib/lace/exceptions.rb +56 -25
- data/lib/lace/package/facts.rb +57 -44
- data/lib/lace/package/package.rb +59 -40
- data/lib/lace/package/pkg_lace.rb +73 -0
- data/lib/lace/package/utils.rb +114 -11
- data/lib/lace/package.rb +1 -0
- data/lib/lace/utils.rb +55 -47
- data/lib/lace/version.rb +1 -1
- data/lib/lace.rb +18 -13
- metadata +3 -3
- data/lib/lace/package_cli.rb +0 -4
data/lib/lace/package/facts.rb
CHANGED
|
@@ -3,7 +3,13 @@
|
|
|
3
3
|
require 'yaml'
|
|
4
4
|
require 'erb'
|
|
5
5
|
|
|
6
|
+
# The parsed .lace.yml of a package. Keys about the package itself (version,
|
|
7
|
+
# homepage, flavors) come from the whole manifest; keys about what to link
|
|
8
|
+
# and run (config_files, setup, post) come from the chosen flavor, or from
|
|
9
|
+
# the whole manifest when it has no flavors.
|
|
6
10
|
class PackageFacts
|
|
11
|
+
MANIFEST = '.lace.yml'
|
|
12
|
+
|
|
7
13
|
attr_reader :facts_file
|
|
8
14
|
|
|
9
15
|
def inspect
|
|
@@ -12,11 +18,11 @@ class PackageFacts
|
|
|
12
18
|
|
|
13
19
|
def initialize(package_path)
|
|
14
20
|
@package_path = Pathname.new(package_path)
|
|
15
|
-
@facts_file = @package_path /
|
|
21
|
+
@facts_file = @package_path / MANIFEST
|
|
16
22
|
raise PackageFactsNotFound, @package_path unless @facts_file.exist?
|
|
17
23
|
|
|
18
|
-
@
|
|
19
|
-
@
|
|
24
|
+
@manifest = facts_file_to_hash
|
|
25
|
+
@facts = @manifest
|
|
20
26
|
end
|
|
21
27
|
|
|
22
28
|
def flavor_with(the_flavor)
|
|
@@ -28,89 +34,96 @@ class PackageFacts
|
|
|
28
34
|
end
|
|
29
35
|
|
|
30
36
|
def config_files
|
|
31
|
-
|
|
32
|
-
@
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
end.flatten
|
|
37
|
-
else
|
|
38
|
-
[] end
|
|
37
|
+
config_file_patterns.map do |path|
|
|
38
|
+
Pathname.glob(@package_path + path).delete_if do |match|
|
|
39
|
+
match.directory? and path.include? '*'
|
|
40
|
+
end
|
|
41
|
+
end.flatten
|
|
39
42
|
end
|
|
40
43
|
|
|
41
44
|
def globbed_folder
|
|
42
|
-
|
|
43
|
-
@facts['config_files'].flatten.select { |f| f.include? '*' }
|
|
44
|
-
else
|
|
45
|
-
[] end
|
|
45
|
+
config_file_patterns.select { |f| f.include? '*' }
|
|
46
46
|
end
|
|
47
47
|
|
|
48
48
|
def has_config_files?
|
|
49
|
-
|
|
49
|
+
!flavor_fact('config_files').nil?
|
|
50
50
|
end
|
|
51
51
|
|
|
52
52
|
def has_flavors?
|
|
53
|
-
|
|
53
|
+
!manifest_fact('flavors').nil?
|
|
54
54
|
end
|
|
55
55
|
|
|
56
56
|
def key?(key)
|
|
57
|
-
@
|
|
57
|
+
@manifest.key?(key) || @facts.key?(key)
|
|
58
58
|
end
|
|
59
59
|
|
|
60
60
|
def version
|
|
61
|
-
|
|
61
|
+
manifest_fact('version')
|
|
62
62
|
end
|
|
63
63
|
|
|
64
|
-
def
|
|
65
|
-
|
|
66
|
-
rescue StandardError
|
|
67
|
-
[]
|
|
64
|
+
def homepage
|
|
65
|
+
manifest_fact('homepage')
|
|
68
66
|
end
|
|
69
67
|
|
|
70
|
-
|
|
71
|
-
|
|
68
|
+
# Optional: the package's own name, used when fetching without --name.
|
|
69
|
+
def name
|
|
70
|
+
manifest_fact('name')
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Optional: one line about the package, shown by `lace ls`.
|
|
74
|
+
def description
|
|
75
|
+
manifest_fact('description')
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def setup_files
|
|
79
|
+
Array(flavor_fact('setup')).flatten
|
|
72
80
|
end
|
|
73
81
|
|
|
74
82
|
def flavors
|
|
75
|
-
|
|
76
|
-
@unflavorable_facts['flavors'].keys.sort
|
|
77
|
-
else
|
|
78
|
-
[]
|
|
79
|
-
end
|
|
83
|
+
(manifest_fact('flavors') || {}).keys.sort
|
|
80
84
|
end
|
|
81
85
|
|
|
82
86
|
def flavor!(the_flavor)
|
|
83
87
|
raise PackageFlavorDoesNotExist.new(the_flavor, flavors) unless flavors.include? the_flavor
|
|
84
88
|
|
|
85
|
-
@facts =
|
|
89
|
+
@facts = manifest_fact('flavors')[the_flavor] || {}
|
|
86
90
|
end
|
|
87
91
|
|
|
88
92
|
def unflavor!
|
|
89
|
-
@facts = @
|
|
93
|
+
@facts = @manifest
|
|
90
94
|
end
|
|
91
95
|
|
|
92
96
|
def post(hook_point)
|
|
93
|
-
|
|
94
|
-
[]
|
|
95
|
-
else
|
|
96
|
-
post_hook = @facts['post']
|
|
97
|
-
(post_hook[hook_point.to_s] || []).flatten
|
|
98
|
-
end
|
|
97
|
+
Array((flavor_fact('post') || {})[hook_point.to_s]).flatten
|
|
99
98
|
end
|
|
100
99
|
|
|
101
100
|
protected
|
|
102
101
|
|
|
102
|
+
# A key of the whole manifest, whatever flavor is chosen.
|
|
103
|
+
def manifest_fact(key)
|
|
104
|
+
@manifest[key]
|
|
105
|
+
end
|
|
106
|
+
|
|
107
|
+
# A key of the chosen flavor, or of the whole manifest without flavors.
|
|
108
|
+
def flavor_fact(key)
|
|
109
|
+
@facts[key]
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
def config_file_patterns
|
|
113
|
+
Array(flavor_fact('config_files')).flatten
|
|
114
|
+
end
|
|
115
|
+
|
|
103
116
|
def facts_file_to_hash
|
|
104
117
|
begin
|
|
105
118
|
rendered_manifest = ERB.new(@facts_file.read, trim_mode: '-').result(binding)
|
|
106
|
-
rescue
|
|
119
|
+
rescue StandardError, ScriptError => e
|
|
107
120
|
raise ManifestErbError.new(self, e)
|
|
108
121
|
end
|
|
109
122
|
value = YAML.safe_load rendered_manifest, aliases: true
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
123
|
+
# An empty manifest, or one holding only '---', has no keys.
|
|
124
|
+
return {} if value.nil? || value == '---'
|
|
125
|
+
raise ManifestNotAMapping, @facts_file unless value.is_a?(Hash)
|
|
126
|
+
|
|
127
|
+
value
|
|
115
128
|
end
|
|
116
129
|
end
|
data/lib/lace/package/package.rb
CHANGED
|
@@ -5,6 +5,7 @@ require 'lace/download_strategy'
|
|
|
5
5
|
|
|
6
6
|
class Package
|
|
7
7
|
include GitCommands
|
|
8
|
+
|
|
8
9
|
attr_reader :name, :facts, :path
|
|
9
10
|
|
|
10
11
|
def initialize(name, flavor = nil)
|
|
@@ -16,27 +17,6 @@ class Package
|
|
|
16
17
|
read_facts!
|
|
17
18
|
end
|
|
18
19
|
|
|
19
|
-
def setup
|
|
20
|
-
return if ARGV.nohooks?
|
|
21
|
-
|
|
22
|
-
ENV['LACEPKG_PATH'] = @path
|
|
23
|
-
@path.cd do
|
|
24
|
-
facts.setup_files.each do |cmd|
|
|
25
|
-
safe_system cmd
|
|
26
|
-
end
|
|
27
|
-
end
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
def after_update
|
|
31
|
-
return if ARGV.nohooks?
|
|
32
|
-
|
|
33
|
-
@path.cd do
|
|
34
|
-
facts.post(:update).each do |cmd|
|
|
35
|
-
system cmd
|
|
36
|
-
end
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
20
|
def is_git_repo?
|
|
41
21
|
@target_folder = @path
|
|
42
22
|
repo_valid?
|
|
@@ -49,17 +29,37 @@ class Package
|
|
|
49
29
|
repo_modified?
|
|
50
30
|
end
|
|
51
31
|
|
|
32
|
+
# How much of the package is linked into $HOME:
|
|
33
|
+
# state :active, :partial or :inactive
|
|
34
|
+
# flavor the flavor judged; nil for a package without flavors
|
|
35
|
+
# unlinked { config file => :missing or :blocked }
|
|
36
|
+
# linked_count config files linked to this package
|
|
37
|
+
Activation = Struct.new(:state, :flavor, :unlinked, :linked_count)
|
|
38
|
+
|
|
52
39
|
def is_active?
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
40
|
+
activation.state == :active
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Without a chosen flavor, judge the flavor closest to fully linked.
|
|
44
|
+
def activation
|
|
45
|
+
return own_activation unless @facts.has_flavors? && @flavor == false
|
|
46
|
+
|
|
47
|
+
by_flavor = @facts.flavors.map { |f| Package.new(@name, f).activation }
|
|
48
|
+
by_flavor.find { |a| a.state == :active } ||
|
|
49
|
+
by_flavor.select { |a| a.state == :partial }.max_by(&:linked_count) ||
|
|
50
|
+
Activation.new(:inactive, nil, {}, 0)
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Activation of the chosen flavor, or of a package without flavors.
|
|
54
|
+
def own_activation
|
|
55
|
+
files = @facts.config_files.uniq
|
|
56
|
+
unlinked = files.to_h { |f| [f, link_state(f)] }.reject { |_, state| state == :linked }
|
|
57
|
+
linked_count = files.size - unlinked.size
|
|
58
|
+
state = if unlinked.empty? then :active
|
|
59
|
+
elsif linked_count.zero? then :inactive
|
|
60
|
+
else :partial
|
|
61
|
+
end
|
|
62
|
+
Activation.new(state, (@flavor if @facts.has_flavors?), unlinked, linked_count)
|
|
63
63
|
end
|
|
64
64
|
|
|
65
65
|
def read_facts!
|
|
@@ -90,17 +90,36 @@ class Package
|
|
|
90
90
|
false
|
|
91
91
|
end
|
|
92
92
|
|
|
93
|
+
# Where a config file stands in $HOME: linked to this package, missing,
|
|
94
|
+
# or blocked by something else (a file, a folder or a foreign link).
|
|
95
|
+
def link_state(file)
|
|
96
|
+
dest = file.as_dotfile(Dir.home, @path)
|
|
97
|
+
return :linked if dest.symlink? && dest.readlink == file
|
|
98
|
+
return :missing unless dest.exist? || dest.symlink?
|
|
99
|
+
|
|
100
|
+
:blocked
|
|
101
|
+
end
|
|
102
|
+
|
|
93
103
|
def link_file(file)
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
FileUtils.mv dest, dest.as_backup
|
|
104
|
+
dest = file.as_dotfile(Dir.home, @path)
|
|
105
|
+
state = link_state(file)
|
|
106
|
+
case state
|
|
107
|
+
when :linked then return
|
|
108
|
+
when :blocked then move_aside(dest, file)
|
|
109
|
+
when :missing then nil
|
|
110
|
+
else raise ArgumentError, "unknown link state: #{state.inspect}"
|
|
102
111
|
end
|
|
103
|
-
link_file_or_directory
|
|
112
|
+
link_file_or_directory file, dest
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# Something else is in the way: refuse, or with --force keep it as *.lace.bak.
|
|
116
|
+
def move_aside(dest, src)
|
|
117
|
+
raise WouldOverwriteError.new(dest, src) unless ARGV.force?
|
|
118
|
+
|
|
119
|
+
backup = dest.as_backup
|
|
120
|
+
raise BackupExistsError, backup if backup.exist? || backup.symlink?
|
|
121
|
+
|
|
122
|
+
FileUtils.mv dest, backup
|
|
104
123
|
end
|
|
105
124
|
|
|
106
125
|
def link_file_or_directory(src, dest, force: ARGV.force?)
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'yaml'
|
|
4
|
+
|
|
5
|
+
# A pkg.lace file: several packages to fetch and set up together, in order.
|
|
6
|
+
#
|
|
7
|
+
# packages:
|
|
8
|
+
# - uri: https://github.com/kairichard/dotfiles.git # required
|
|
9
|
+
# name: kairichard # optional, like --name
|
|
10
|
+
# flavor: macos # optional
|
|
11
|
+
#
|
|
12
|
+
# The whole file is checked before any package is touched.
|
|
13
|
+
class PkgLace
|
|
14
|
+
EXTENSION = '.lace'
|
|
15
|
+
ENTRY_KEYS = %w[uri name flavor].freeze
|
|
16
|
+
|
|
17
|
+
# source is the uri as written, for messages; uri is resolved for fetching.
|
|
18
|
+
Entry = Struct.new(:source, :uri, :name, :flavor) do
|
|
19
|
+
def label
|
|
20
|
+
name || source
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
attr_reader :path, :entries
|
|
25
|
+
|
|
26
|
+
def self.path?(arg)
|
|
27
|
+
arg.to_s.end_with?(EXTENSION)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def initialize(path)
|
|
31
|
+
@path = Pathname.new(path).expand_path
|
|
32
|
+
raise PkgLaceNotFound, path unless @path.file?
|
|
33
|
+
|
|
34
|
+
@entries = parse
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
def parse
|
|
40
|
+
data = YAML.safe_load(@path.read)
|
|
41
|
+
packages = data['packages'] if data.is_a?(Hash)
|
|
42
|
+
unless packages.is_a?(Array) && !packages.empty?
|
|
43
|
+
raise InvalidPkgLace.new(@path,
|
|
44
|
+
"needs a non-empty 'packages' list")
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
packages.each_with_index.map { |entry, index| parse_entry(entry, index + 1) }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def parse_entry(entry, number)
|
|
51
|
+
raise InvalidPkgLace.new(@path, "entry #{number} must be keys and values") unless entry.is_a?(Hash)
|
|
52
|
+
|
|
53
|
+
unknown = entry.keys - ENTRY_KEYS
|
|
54
|
+
raise InvalidPkgLace.new(@path, "entry #{number} has unknown keys: #{unknown.join(', ')}") unless unknown.empty?
|
|
55
|
+
|
|
56
|
+
uri = entry['uri']
|
|
57
|
+
raise InvalidPkgLace.new(@path, "entry #{number} needs a uri") unless uri.is_a?(String) && !uri.empty?
|
|
58
|
+
|
|
59
|
+
%w[name flavor].each do |key|
|
|
60
|
+
next if entry[key].nil? || entry[key].is_a?(String)
|
|
61
|
+
|
|
62
|
+
raise InvalidPkgLace.new(@path, "entry #{number}: #{key} must be text")
|
|
63
|
+
end
|
|
64
|
+
Entry.new(uri, resolve(uri), entry['name'], entry['flavor'])
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
# A local path is read relative to the pkg.lace file; anything else
|
|
68
|
+
# (a URL, git@..., user/repo) passes through unchanged.
|
|
69
|
+
def resolve(uri)
|
|
70
|
+
local = @path.dirname / uri
|
|
71
|
+
local.exist? ? local.to_s : uri
|
|
72
|
+
end
|
|
73
|
+
end
|
data/lib/lace/package/utils.rb
CHANGED
|
@@ -2,17 +2,63 @@
|
|
|
2
2
|
|
|
3
3
|
require('lace/exceptions')
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
# How $HOME differs from a package's manifest:
|
|
6
|
+
# added config files with nothing in their place yet
|
|
7
|
+
# removed links into the package that the manifest no longer lists
|
|
8
|
+
# blocked config files whose place holds a file, folder or foreign link
|
|
9
|
+
Diff = Struct.new(:added, :removed, :blocked) do
|
|
10
|
+
def in_sync?
|
|
11
|
+
added.empty? && removed.empty? && blocked.empty?
|
|
12
|
+
end
|
|
6
13
|
end
|
|
7
14
|
|
|
8
15
|
class PackageUtils
|
|
16
|
+
# A package name is a folder name inside the packages folder.
|
|
17
|
+
PACKAGE_NAME = /\A[A-Za-z0-9][A-Za-z0-9._-]*\z/
|
|
18
|
+
|
|
19
|
+
# Fetch a package and return [name, folder]. Without --name, a name in the
|
|
20
|
+
# package's own manifest wins over the one derived from its URI. A fetch
|
|
21
|
+
# that ends without a valid, named package leaves nothing behind.
|
|
9
22
|
def self.fetch(uri, desired_package_name = nil)
|
|
23
|
+
validate_name!(desired_package_name) if desired_package_name
|
|
10
24
|
downloader_cls = DownloadStrategyDetector.detect(uri)
|
|
11
25
|
downloader = downloader_cls.new(uri, desired_package_name)
|
|
12
26
|
raise(PackageAlreadyInstalled, downloader.target_folder) if downloader.target_folder.exist?
|
|
13
27
|
|
|
28
|
+
# A fresh machine has no packages folder yet.
|
|
29
|
+
Lace.pkgs_folder.mkpath
|
|
14
30
|
downloader.fetch
|
|
15
|
-
|
|
31
|
+
begin
|
|
32
|
+
name, folder = if desired_package_name
|
|
33
|
+
[downloader.name,
|
|
34
|
+
downloader.target_folder]
|
|
35
|
+
else
|
|
36
|
+
adopt_manifest_name(downloader)
|
|
37
|
+
end
|
|
38
|
+
Package.new(name, false)
|
|
39
|
+
[name, folder]
|
|
40
|
+
rescue PackageFactsNotFound, InvalidPackageName, PackageAlreadyInstalled
|
|
41
|
+
onoe 'Removing fetched files'
|
|
42
|
+
FileUtils.rm_rf(downloader.target_folder)
|
|
43
|
+
raise
|
|
44
|
+
end
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def self.validate_name!(name)
|
|
48
|
+
raise InvalidPackageName, name unless name.match?(PACKAGE_NAME)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Move the fetched folder to the name its manifest gives, if it gives one.
|
|
52
|
+
def self.adopt_manifest_name(downloader)
|
|
53
|
+
manifest_name = PackageFacts.new(downloader.target_folder).name
|
|
54
|
+
return [downloader.name, downloader.target_folder] if manifest_name.nil? || manifest_name == downloader.name
|
|
55
|
+
|
|
56
|
+
validate_name!(manifest_name)
|
|
57
|
+
target = Lace.pkgs_folder / manifest_name
|
|
58
|
+
raise PackageAlreadyInstalled, target if target.exist?
|
|
59
|
+
|
|
60
|
+
FileUtils.mv downloader.target_folder, target
|
|
61
|
+
[manifest_name, target]
|
|
16
62
|
end
|
|
17
63
|
|
|
18
64
|
def self.remove(package_name)
|
|
@@ -23,15 +69,75 @@ class PackageUtils
|
|
|
23
69
|
FileUtils.rm_rf(package.path)
|
|
24
70
|
end
|
|
25
71
|
|
|
72
|
+
# Run hook commands from the package folder, with LACEPKG_PATH set.
|
|
73
|
+
# A failing hook raises like any other failed step.
|
|
74
|
+
def self.run_hooks(package, commands)
|
|
75
|
+
return if ARGV.nohooks?
|
|
76
|
+
|
|
77
|
+
ENV['LACEPKG_PATH'] = package.path.to_s
|
|
78
|
+
package.path.cd { commands.each { |cmd| safe_system cmd } }
|
|
79
|
+
end
|
|
80
|
+
|
|
26
81
|
def self.setup(package_name)
|
|
27
82
|
package = Package.new(package_name, ARGV.first)
|
|
28
83
|
package.activate!
|
|
29
|
-
package.
|
|
84
|
+
run_hooks(package, package.facts.setup_files)
|
|
30
85
|
rescue StandardError => e
|
|
31
86
|
onoe(e.message)
|
|
32
87
|
odie('Package remains installed but was not activated')
|
|
33
88
|
end
|
|
34
89
|
|
|
90
|
+
# Set up every package of a pkg.lace in order. A failing package does not
|
|
91
|
+
# stop the others; the failures are reported at the end.
|
|
92
|
+
def self.setup_all(pkg_lace)
|
|
93
|
+
failures = pkg_lace.entries.filter_map do |entry|
|
|
94
|
+
setup_entry(entry)
|
|
95
|
+
nil
|
|
96
|
+
rescue StandardError => e
|
|
97
|
+
[entry, e]
|
|
98
|
+
end
|
|
99
|
+
return if failures.empty?
|
|
100
|
+
|
|
101
|
+
failures.each { |entry, error| onoe "#{entry.label}: #{error.message}" }
|
|
102
|
+
ofail "#{failures.size} of #{pkg_lace.entries.size} packages failed"
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Fetch the entry unless installed, then link and run setup hooks;
|
|
106
|
+
# a partly linked package only gets its missing links, an active one nothing.
|
|
107
|
+
def self.setup_entry(entry)
|
|
108
|
+
name = installed_name(entry) || fetch_entry(entry)
|
|
109
|
+
package = Package.new(name, entry.flavor)
|
|
110
|
+
raise PackageFlavorDoesNotExist.new(entry.flavor, []) if entry.flavor && !package.facts.has_flavors?
|
|
111
|
+
|
|
112
|
+
state = package.activation.state
|
|
113
|
+
case state
|
|
114
|
+
when :active
|
|
115
|
+
ohai "#{name}: already active, skipped"
|
|
116
|
+
when :partial
|
|
117
|
+
ohai "#{name}: linking what is missing"
|
|
118
|
+
package.activate!
|
|
119
|
+
when :inactive
|
|
120
|
+
ohai "#{name}: setting up#{" (#{entry.flavor})" if entry.flavor}"
|
|
121
|
+
package.activate!
|
|
122
|
+
run_hooks(package, package.facts.setup_files)
|
|
123
|
+
else
|
|
124
|
+
raise ArgumentError, "unknown activation state: #{state.inspect}"
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# The name an entry is installed under, if it is installed already.
|
|
129
|
+
def self.installed_name(entry)
|
|
130
|
+
name = entry.name || DownloadStrategyDetector.detect(entry.uri).new(entry.uri, nil).name
|
|
131
|
+
name if (Lace.pkgs_folder / name).exist?
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def self.fetch_entry(entry)
|
|
135
|
+
fetch(entry.uri, entry.name).first
|
|
136
|
+
rescue PackageAlreadyInstalled => e
|
|
137
|
+
# Installed earlier under the name its manifest gives: use that package.
|
|
138
|
+
e.location.basename.to_s
|
|
139
|
+
end
|
|
140
|
+
|
|
35
141
|
def self.deactivate(package_name)
|
|
36
142
|
package = Package.new(package_name, ARGV.first)
|
|
37
143
|
raise(NonActiveFlavorError) unless package.is_active? || ARGV.force?
|
|
@@ -59,24 +165,21 @@ class PackageUtils
|
|
|
59
165
|
updater.update
|
|
60
166
|
activate(package_name) if was_active_before_update
|
|
61
167
|
package = Package.new(package_name, false)
|
|
62
|
-
package.
|
|
168
|
+
run_hooks(package, package.facts.post(:update))
|
|
63
169
|
end
|
|
64
170
|
|
|
65
171
|
def self.diff(package_name)
|
|
66
|
-
home_dir = Dir.home
|
|
67
172
|
package = Package.new(package_name, ARGV.first)
|
|
68
173
|
config_files = Set.new(package.facts.config_files)
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
end)
|
|
73
|
-
Diff.new(files_from_manifest_not_in_home, (files_pointing_to_package - config_files))
|
|
174
|
+
by_state = config_files.group_by { |f| package.link_state(f) }
|
|
175
|
+
stale_links = symlinks_to_package(package) - config_files
|
|
176
|
+
Diff.new(Set.new(by_state.fetch(:missing, [])), stale_links, Set.new(by_state.fetch(:blocked, [])))
|
|
74
177
|
end
|
|
75
178
|
|
|
76
179
|
def self.symlinks_to_package(package)
|
|
77
180
|
home_dir = Dir.home
|
|
78
181
|
found_links = Set.new
|
|
79
|
-
traverse_directory(home_dir, package) { |entry|
|
|
182
|
+
traverse_directory(home_dir, package) { |entry| found_links << Pathname.new(File.readlink(entry)) }
|
|
80
183
|
found_links
|
|
81
184
|
end
|
|
82
185
|
end
|
data/lib/lace/package.rb
CHANGED