I need to copy a folder between two contexts.
There exists some aliases relying on cat to copy given files (e.g., local2in).
Following this idea, I tried to transfer the folder structure with tar:
…
- pipe:
- exec_local: tar --create --directory=$${kameleon_data_dir} -- xpctl
- exec_in: tar --directory=$${dest} --extract
…
where xpctl is the folder I want to copy.
The --directory option of tar change to the directory before performing any operation (as documented in tar manual).
It is required, otherwise tar includes the full path to my folder, and the extraction in the other context is not correctly located.
This snippet fails with the following error (verbose output enabled):
[info] Looking for data ' -- xpctl'
[info] /path/to/kameleon/recipe/steps/data/ -- xpctl : nonexistent
[info] /path/to/kameleon/recipe/steps/data/ -- xpctl : nonexistent
Error: Cannot find data ' -- xpctl' used in '/path/to/kameleon/recipe/steps/setup/xpctl.yaml'
Digging a bit deeper into kameleon code base, this seems related to the regexp (see l. 21 & l. 24) used in resolve_data_dir_vars:
|
def self.resolve_data_dir_vars(raw, yaml_path, initial_variables, recipe, kwargs) |
|
raw.to_s.scan(/\$\$kameleon\_data\_dir\/(.*)/) do |var| |
|
warn_var(var) |
|
end |
|
reg = %r/(\$\$kameleon\_data\_dir|\$\${kameleon\_data\_dir})(.*)/ |
|
matches = raw.to_enum(:scan, reg).map { Regexp.last_match } |
|
matches.each do |m| |
|
unless m.nil? |
|
path = resolve_simple_vars(m[2], yaml_path, initial_variables, kwargs) |
|
resolved_path = recipe.resolve_data_path(path.chomp('"'), yaml_path) |
|
raw.gsub!(m[0].chomp('"'), "#{resolved_path}") |
|
end |
|
end |
|
return raw |
|
end |
The regexp ends with (.*), and forbid the use of $${kameleon_data_dir} on its own.
Patching the regexp to end with (\S*) seemed to make the recipe works, but it changes the semantic, and forbids paths containing spaces to be used.
Maybe the regexp ((\S|\\\s)*) would be better by allowing spaces to be used when properly escaped.
If there is a simpler solution to copy the whole folder, I'm happy with it too 😃
I need to copy a folder between two contexts.
There exists some aliases relying on
catto copy given files (e.g.,local2in).Following this idea, I tried to transfer the folder structure with
tar:where
xpctlis the folder I want to copy.The
--directoryoption oftarchange to the directory before performing any operation (as documented in tar manual).It is required, otherwise
tarincludes the full path to my folder, and the extraction in the other context is not correctly located.This snippet fails with the following error (verbose output enabled):
Digging a bit deeper into
kameleoncode base, this seems related to the regexp (see l. 21 & l. 24) used inresolve_data_dir_vars:kameleon/lib/kameleon/utils.rb
Lines 20 to 34 in 7e7026d
The regexp ends with
(.*), and forbid the use of$${kameleon_data_dir}on its own.Patching the regexp to end with
(\S*)seemed to make the recipe works, but it changes the semantic, and forbids paths containing spaces to be used.Maybe the regexp
((\S|\\\s)*)would be better by allowing spaces to be used when properly escaped.If there is a simpler solution to copy the whole folder, I'm happy with it too 😃