Class: Chef::Provider::RemoteFile::LocalFile

Inherits:
Object
  • Object
show all
Defined in:
lib/chef/provider/remote_file/local_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(uri, new_resource, current_resource) ⇒ LocalFile

Returns a new instance of LocalFile.



31
32
33
34
# File 'lib/chef/provider/remote_file/local_file.rb', line 31

def initialize(uri, new_resource, current_resource)
  @new_resource = new_resource
  @uri = uri
end

Instance Attribute Details

#new_resourceObject (readonly)

Returns the value of attribute new_resource.



29
30
31
# File 'lib/chef/provider/remote_file/local_file.rb', line 29

def new_resource
  @new_resource
end

#uriObject (readonly)

Returns the value of attribute uri.



28
29
30
# File 'lib/chef/provider/remote_file/local_file.rb', line 28

def uri
  @uri
end

Instance Method Details

#fetchObject

Fetches the file at uri, returning a Tempfile-like File handle



49
50
51
52
53
54
55
# File 'lib/chef/provider/remote_file/local_file.rb', line 49

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



37
38
39
# File 'lib/chef/provider/remote_file/local_file.rb', line 37

def fix_windows_path(path)
  path.gsub(%r{^/([a-zA-Z]:)}, '\1')
end

#source_pathObject



41
42
43
44
45
46
# File 'lib/chef/provider/remote_file/local_file.rb', line 41

def source_path
  @source_path ||= begin
    path = URI.unescape(uri.path)
    ChefUtils.windows? ? fix_windows_path(path) : path
  end
end