Class: Chef::Provider::RemoteFile::NetworkFile

Inherits:
Object
  • Object
show all
Includes:
Mixin::UserContext
Defined in:
lib/chef/provider/remote_file/network_file.rb

Constant Summary collapse

TRANSFER_CHUNK_SIZE =
1048576

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source, new_resource, current_resource) ⇒ NetworkFile

Returns a new instance of NetworkFile.



34
35
36
37
# File 'lib/chef/provider/remote_file/network_file.rb', line 34

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

Instance Attribute Details

#new_resourceObject (readonly)

Returns the value of attribute new_resource.



30
31
32
# File 'lib/chef/provider/remote_file/network_file.rb', line 30

def new_resource
  @new_resource
end

Instance Method Details

#fetchObject

Fetches the file on a network share, returning a Tempfile-like File handle windows only



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/chef/provider/remote_file/network_file.rb', line 41

def fetch
  begin
    tempfile = Chef::FileContentManagement::Tempfile.new(new_resource).tempfile
    Chef::Log.trace("#{new_resource} staging #{@source} to #{tempfile.path}")

    with_user_context(new_resource.remote_user, new_resource.remote_password, new_resource.remote_domain, new_resource.authentication) do
      ::File.open(@source, "rb") do |remote_file|
        while data = remote_file.read(TRANSFER_CHUNK_SIZE)
          tempfile.write(data)
        end
      end
    end
  ensure
    tempfile.close if tempfile
  end
  tempfile
end