knife-essentials 0.7.2 → 0.7.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/chef_fs/file_pattern.rb +10 -10
- data/lib/chef_fs/file_system/chef_repository_file_system_entry.rb +2 -2
- data/lib/chef_fs/file_system/cookbook_dir.rb +1 -15
- data/lib/chef_fs/file_system/cookbooks_dir.rb +22 -0
- data/lib/chef_fs/file_system/file_system_entry.rb +1 -1
- data/lib/chef_fs/file_system.rb +13 -3
- data/lib/chef_fs/knife.rb +2 -2
- data/lib/chef_fs/path_utils.rb +2 -2
- data/lib/chef_fs/version.rb +1 -1
- metadata +2 -2
data/lib/chef_fs/file_pattern.rb
CHANGED
@@ -53,7 +53,7 @@ module ChefFS
|
|
53
53
|
def could_match_children?(path)
|
54
54
|
return false if path == '' # Empty string is not a path
|
55
55
|
|
56
|
-
argument_is_absolute = !!(path
|
56
|
+
argument_is_absolute = !!(path =~ /^#{ChefFS::PathUtils::regexp_path_separator}/)
|
57
57
|
return false if is_absolute != argument_is_absolute
|
58
58
|
path = path[1,path.length-1] if argument_is_absolute
|
59
59
|
|
@@ -89,10 +89,10 @@ module ChefFS
|
|
89
89
|
# abc/*/ghi.exact_child_name_under('abc') == nil
|
90
90
|
# abc/*/ghi.exact_child_name_under('abc/def') == 'ghi'
|
91
91
|
# abc/**/ghi.exact_child_name_under('abc/def') == nil
|
92
|
-
#
|
92
|
+
#
|
93
93
|
# This method assumes +could_match_children?(path)+ is +true+.
|
94
94
|
def exact_child_name_under(path)
|
95
|
-
path = path[1,path.length-1] if !!(path
|
95
|
+
path = path[1,path.length-1] if !!(path =~ /^#{ChefFS::PathUtils::regexp_path_separator}/)
|
96
96
|
dirs_in_path = ChefFS::PathUtils::split(path).length
|
97
97
|
return nil if exact_parts.length <= dirs_in_path
|
98
98
|
return exact_parts[dirs_in_path]
|
@@ -130,7 +130,7 @@ module ChefFS
|
|
130
130
|
# abc/*/def.match?('abc/foo/def') == true
|
131
131
|
# abc/*/def.match?('abc/foo') == false
|
132
132
|
def match?(path)
|
133
|
-
argument_is_absolute = !!(path
|
133
|
+
argument_is_absolute = !!(path =~ /^#{ChefFS::PathUtils::regexp_path_separator}/)
|
134
134
|
return false if is_absolute != argument_is_absolute
|
135
135
|
path = path[1,path.length-1] if argument_is_absolute
|
136
136
|
!!regexp.match(path)
|
@@ -267,15 +267,15 @@ module ChefFS
|
|
267
267
|
exact = nil
|
268
268
|
regexp << '.'
|
269
269
|
else
|
270
|
-
if part[0] == '\\' && part.length == 2
|
270
|
+
if part[0,1] == '\\' && part.length == 2
|
271
271
|
# backslash escapes are only supported on Unix, and are handled here by leaving the escape on (it means the same thing in a regex)
|
272
|
-
exact << part[1] if !exact.nil?
|
273
|
-
if regexp_escape_characters.include?(part[1])
|
272
|
+
exact << part[1,1] if !exact.nil?
|
273
|
+
if regexp_escape_characters.include?(part[1,1])
|
274
274
|
regexp << part
|
275
275
|
else
|
276
|
-
regexp << part[1]
|
276
|
+
regexp << part[1,1]
|
277
277
|
end
|
278
|
-
elsif part[0] == '[' && part.length > 1
|
278
|
+
elsif part[0,1] == '[' && part.length > 1
|
279
279
|
# [...] happens only on Unix, and is handled here by *not* backslashing (it means the same thing in and out of regex)
|
280
280
|
exact = nil
|
281
281
|
regexp << part
|
@@ -289,4 +289,4 @@ module ChefFS
|
|
289
289
|
[regexp, exact, has_double_star]
|
290
290
|
end
|
291
291
|
end
|
292
|
-
end
|
292
|
+
end
|
@@ -40,8 +40,8 @@ module ChefFS
|
|
40
40
|
end
|
41
41
|
|
42
42
|
def children
|
43
|
-
@children ||= Dir.entries(file_path).select { |entry| entry != '.' && entry != '..' && !ignored?(entry) }
|
44
|
-
|
43
|
+
@children ||= Dir.entries(file_path).select { |entry| entry != '.' && entry != '..' && !ignored?(entry) }.
|
44
|
+
map { |entry| ChefRepositoryFileSystemEntry.new(entry, self) }
|
45
45
|
end
|
46
46
|
|
47
47
|
attr_reader :chefignore
|
@@ -114,21 +114,7 @@ module ChefFS
|
|
114
114
|
end
|
115
115
|
|
116
116
|
def copy_from(other)
|
117
|
-
|
118
|
-
# TODO this only works on the file system. And it can't be broken into
|
119
|
-
# pieces.
|
120
|
-
begin
|
121
|
-
Chef::CookbookUploader.new(other_cookbook_version, other.parent.file_path).upload_cookbook
|
122
|
-
rescue Net::HTTPServerException => e
|
123
|
-
case e.response.code
|
124
|
-
when "409"
|
125
|
-
ui.error "Version #{cookbook.version} of cookbook #{cookbook.name} is frozen. Use --force to override."
|
126
|
-
Log.debug(e)
|
127
|
-
raise Exceptions::CookbookFrozen
|
128
|
-
else
|
129
|
-
raise
|
130
|
-
end
|
131
|
-
end
|
117
|
+
parent.upload_cookbook_from(other)
|
132
118
|
end
|
133
119
|
|
134
120
|
def rest
|
@@ -17,6 +17,28 @@ module ChefFS
|
|
17
17
|
@children ||= rest.get_rest(api_path).map { |key, value| CookbookDir.new(key, self, value) }
|
18
18
|
end
|
19
19
|
|
20
|
+
def create_child_from(other)
|
21
|
+
upload_cookbook_from(other)
|
22
|
+
end
|
23
|
+
|
24
|
+
def upload_cookbook_from(other)
|
25
|
+
other_cookbook_version = other.chef_object
|
26
|
+
# TODO this only works on the file system. And it can't be broken into
|
27
|
+
# pieces.
|
28
|
+
begin
|
29
|
+
Chef::CookbookUploader.new(other_cookbook_version, other.parent.file_path).upload_cookbook
|
30
|
+
rescue Net::HTTPServerException => e
|
31
|
+
case e.response.code
|
32
|
+
when "409"
|
33
|
+
ui.error "Version #{other_cookbook_version.version} of cookbook #{other_cookbook_version.name} is frozen. Use --force to override."
|
34
|
+
Chef::Log.debug(e)
|
35
|
+
raise Exceptions::CookbookFrozen
|
36
|
+
else
|
37
|
+
raise
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
20
42
|
def can_have_child?(name, is_dir)
|
21
43
|
is_dir
|
22
44
|
end
|
data/lib/chef_fs/file_system.rb
CHANGED
@@ -53,8 +53,8 @@ module ChefFS
|
|
53
53
|
#
|
54
54
|
def self.resolve_path(entry, path)
|
55
55
|
return entry if path.length == 0
|
56
|
-
return resolve_path(entry.root, path) if path[0] == "/" && entry.root != entry
|
57
|
-
if path[0] == "/"
|
56
|
+
return resolve_path(entry.root, path) if path[0,1] == "/" && entry.root != entry
|
57
|
+
if path[0,1] == "/"
|
58
58
|
path = path[1,path.length-1]
|
59
59
|
end
|
60
60
|
|
@@ -226,6 +226,17 @@ module ChefFS
|
|
226
226
|
|
227
227
|
elsif !dest_entry.exists?
|
228
228
|
if new_dest_parent.can_have_child?(src_entry.name, src_entry.dir?)
|
229
|
+
# If the entry can do a copy directly from filesystem, do that.
|
230
|
+
if new_dest_parent.respond_to?(:create_child_from)
|
231
|
+
if options[:dry_run]
|
232
|
+
puts "Would create #{dest_entry.path_for_printing}"
|
233
|
+
else
|
234
|
+
new_dest_parent.create_child_from(src_entry)
|
235
|
+
puts "Created #{dest_entry.path_for_printing}"
|
236
|
+
end
|
237
|
+
return
|
238
|
+
end
|
239
|
+
|
229
240
|
if src_entry.dir?
|
230
241
|
if options[:dry_run]
|
231
242
|
puts "Would create #{dest_entry.path_for_printing}"
|
@@ -260,7 +271,6 @@ module ChefFS
|
|
260
271
|
if options[:dry_run]
|
261
272
|
puts "Would update #{dest_entry.path_for_printing}"
|
262
273
|
else
|
263
|
-
puts "Updating #{dest_entry.path_for_printing} ..."
|
264
274
|
dest_entry.copy_from(src_entry)
|
265
275
|
puts "Updated #{dest_entry.path_for_printing}"
|
266
276
|
end
|
data/lib/chef_fs/knife.rb
CHANGED
@@ -15,7 +15,7 @@ module ChefFS
|
|
15
15
|
|
16
16
|
def base_path
|
17
17
|
@base_path ||= begin
|
18
|
-
relative_to_base = ChefFS::PathUtils::relative_to(File.
|
18
|
+
relative_to_base = ChefFS::PathUtils::relative_to(File.expand_path(Dir.pwd), chef_repo)
|
19
19
|
relative_to_base == '.' ? '/' : "/#{relative_to_base}"
|
20
20
|
end
|
21
21
|
end
|
@@ -25,7 +25,7 @@ module ChefFS
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def chef_repo
|
28
|
-
@chef_repo ||= File.
|
28
|
+
@chef_repo ||= File.expand_path(File.join(Chef::Config.cookbook_path, ".."))
|
29
29
|
end
|
30
30
|
|
31
31
|
def format_path(path)
|
data/lib/chef_fs/path_utils.rb
CHANGED
@@ -23,7 +23,7 @@ module ChefFS
|
|
23
23
|
def self.join(*parts)
|
24
24
|
return "" if parts.length == 0
|
25
25
|
# Determine if it started with a slash
|
26
|
-
absolute = parts[0].length == 0 || parts[0].length > 0 && parts[0]
|
26
|
+
absolute = parts[0].length == 0 || parts[0].length > 0 && parts[0] =~ /^#{regexp_path_separator}/
|
27
27
|
# Remove leading and trailing slashes from each part so that the join will work (and the slash at the end will go away)
|
28
28
|
parts = parts.map { |part| part.gsub(/^\/|\/$/, "") }
|
29
29
|
# Don't join empty bits
|
@@ -41,4 +41,4 @@ module ChefFS
|
|
41
41
|
end
|
42
42
|
|
43
43
|
end
|
44
|
-
end
|
44
|
+
end
|
data/lib/chef_fs/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knife-essentials
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-05-
|
12
|
+
date: 2012-05-26 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: Universal knife verbs that work with your Chef repository
|
15
15
|
email: jkeiser@opscode.com
|