Skip to content

Instantly share code, notes, and snippets.

@bluSch
Last active August 29, 2015 13:56
Show Gist options
  • Save bluSch/9210142 to your computer and use it in GitHub Desktop.
Save bluSch/9210142 to your computer and use it in GitHub Desktop.
Create all directories in a path with chef
# This function is equivalent to `execute "mkdir -p #{path}"`
# path is the path to be created, and can only be absolute without tweaking this
require 'pathname'
def create_path path
split_path = Pathname(path).each_filename.to_a
split_path.each_with_index.map do | _, index |
partial_path = File.join(File::SEPARATOR, split_path.slice(0, index + 1))
directory partial_path
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment