Method: Chef::ChefFS::FileSystem::Repository::ChefRepositoryFileSystemCookbookDir#write

Defined in:
lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb

#write(cookbook_path, cookbook_version_json, from_fs) ⇒ Object



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'lib/chef/chef_fs/file_system/repository/chef_repository_file_system_cookbook_dir.rb', line 64

def write(cookbook_path, cookbook_version_json, from_fs)
  # Use the copy/diff algorithm to copy it down so we don't destroy
  # chefignored data.  This is terribly un-thread-safe.
  Chef::ChefFS::FileSystem.copy_to(Chef::ChefFS::FilePattern.new("/#{cookbook_path}"), from_fs, self, nil, { :purge => true })

  # Write out .uploaded-cookbook-version.json
  # cookbook_file_path = File.join(file_path, cookbook_name) <- this should be the same as self.file_path
  if !File.exists?(file_path)
    FileUtils.mkdir_p(file_path)
  end
  uploaded_cookbook_version_path = File.join(file_path, Chef::Cookbook::CookbookVersionLoader::UPLOADED_COOKBOOK_VERSION_FILE)
  File.open(uploaded_cookbook_version_path, "w") do |file|
    file.write(cookbook_version_json)
  end
end