Class: Chef::Provider::RemoteFile::LocalFile
- Inherits:
-
Object
- Object
- Chef::Provider::RemoteFile::LocalFile
- Defined in:
- lib/chef/provider/remote_file/local_file.rb
Instance Attribute Summary collapse
-
#new_resource ⇒ Object
readonly
Returns the value of attribute new_resource.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
-
#fetch ⇒ Object
Fetches the file at uri, returning a Tempfile-like File handle.
-
#fix_windows_path(path) ⇒ Object
CHEF-4472: Remove the leading slash from windows paths that we receive from a file:// URI.
-
#initialize(uri, new_resource, current_resource) ⇒ LocalFile
constructor
A new instance of LocalFile.
- #source_path ⇒ Object
Constructor Details
#initialize(uri, new_resource, current_resource) ⇒ LocalFile
Returns a new instance of LocalFile.
32 33 34 35 |
# File 'lib/chef/provider/remote_file/local_file.rb', line 32 def initialize(uri, new_resource, current_resource) @new_resource = new_resource @uri = uri end |
Instance Attribute Details
#new_resource ⇒ Object (readonly)
Returns the value of attribute new_resource.
30 31 32 |
# File 'lib/chef/provider/remote_file/local_file.rb', line 30 def new_resource @new_resource end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
29 30 31 |
# File 'lib/chef/provider/remote_file/local_file.rb', line 29 def uri @uri end |
Instance Method Details
#fetch ⇒ Object
Fetches the file at uri, returning a Tempfile-like File handle
50 51 52 53 54 55 56 |
# File 'lib/chef/provider/remote_file/local_file.rb', line 50 def fetch tempfile = Chef::FileContentManagement::Tempfile.new(new_resource).tempfile Chef::Log.trace("#{new_resource} staging #{source_path} to #{tempfile.path}") FileUtils.cp(source_path, tempfile.path) tempfile.close if tempfile tempfile end |
#fix_windows_path(path) ⇒ Object
CHEF-4472: Remove the leading slash from windows paths that we receive from a file:// URI
38 39 40 |
# File 'lib/chef/provider/remote_file/local_file.rb', line 38 def fix_windows_path(path) path.gsub(%r{^/([a-zA-Z]:)}, '\1') end |
#source_path ⇒ Object
42 43 44 45 46 47 |
# File 'lib/chef/provider/remote_file/local_file.rb', line 42 def source_path @source_path ||= begin path = CGI.unescape(uri.path) ChefUtils.windows? ? fix_windows_path(path) : path end end |