[chef] Platform-independent path normalization in guards, etc.


Chronological Thread 
  • From: Jeff Blaine < >
  • To:
  • Subject: [chef] Platform-independent path normalization in guards, etc.
  • Date: Thu, 28 May 2015 19:58:14 -0400

What's a good pattern for platform-independent path normalization in
guards, execute commands, etc.

Are there libs for this by chance? I'm ignorant as I'm not a
cross-platform ruby developer and also trying to do it a "Chef way" vs.
a pure-ruby way if possible.

For example:

if platform?('windows')
  diffcmd = 'fc'
  catcmd = 'type'
else
  diffcmd = 'diff'
  catcmd = 'cat'
end

execute "Really, something that HAS TO be an execute" do
  not_if "#{diffcmd} some-file other-file"
  # This breaks on Windows due to '/'
  command "#{catcmd} #{Chef::Config[:file_cache_path]}/noodle >>
/chef/humor-me"
end

Thanks for ideas.



Archive powered by MHonArc 2.6.16.

§