Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Copy folder structure between context #124

Open
bleuse opened this issue Jan 14, 2021 · 0 comments
Open

Copy folder structure between context #124

bleuse opened this issue Jan 14, 2021 · 0 comments

Comments

@bleuse
Copy link

bleuse commented Jan 14, 2021

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 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant