Issue #11929 has been updated by Josh Cooper.

Status changed from Code Insufficient to In Topic Branch Pending Review

Fixed the failing test and pushed the new changes.

About whether we should always open files in binary mode, in general, yes, 
except when managing files on Windows that are accessed by other programs that 
require '\r\n' line endings. The problem, is we don't know what the set of all 
programs that may require '\r\n' line endings is.

There's also the usability issue of preserving '\r\n' line endings for files 
that users are likely to edit, e.g. puppet.conf. Most editors are able to deal 
with just '\n' line endings, after all, it is 2012, but there's still good old 
notepad, brain dead as ever.

As for optimizing this so we don't have to open-code that binary mode must be 
explicitly requested, we could patch File.read, but most of the IO singleton 
methods accept a mode argument. Would we patch all of them too? Seems we would 
have to. Except if the caller explicitly requests text mode? Now it's getting 
complicated.

We could monkey patch IO.binread for pre-1.9 ruby's, so at least we don't need 
a puppet-specific method:

<pre>
class IO
  def self.binread(name, length = nil, offset = nil)
    File.open(name, 'rb') do |f|
      f.seek(offset) if offset
      f.read(length)
    end
  end unless singleton_methods.include? :binread
end
</pre>

----------------------------------------
Bug #11929: Cannot serve local binary files on Windows
https://projects.puppetlabs.com/issues/11929

Author: Josh Cooper
Status: In Topic Branch Pending Review
Priority: Normal
Assignee: Josh Cooper
Category: windows
Target version: 2.7.x
Affected Puppet version: 2.7.6
Keywords: 
Branch: https://github.com/puppetlabs/puppet/pull/331


`Puppet::FileServing::Content.content` is not specifying binary mode when 
reading its file. This is okay when the code runs on a Unix master. But if the 
Windows agent is its own fileserver, such as retrieving files from a local 
module, then the file is opened in text mode, which corrupts binaries.

To reproduce:

Given a module:
<pre>
C:\modules
└splunk
    ├files
    │   splunk-4.2.4-110225-x64-release.msi
    └manifests
        init.pp
</pre>

Where init.pp is:

<pre>
class splunk {
  file { 'c:\packages\splunk-4.2.4-110225-x64-release.msi':
    ensure => present,
    source => 'puppet:///modules/splunk/splunk-4.2.4-110225-x64-release.msi',
  }

  package { 'splunk':
    ensure => installed,
    provider => 'msi',
    source => 'c:\packages\splunk-4.2.4-110225-x64-release.msi',
    install_options => { 'INSTALLDIR' => 'C:\splunk' },
    require => File['c:\packages\splunk-4.2.4-110225-x64-release.msi'],
  }
}
</pre>

And site.pp:

<pre>
class { 'splunk': }
</pre>

Trying to apply the local module: 

<pre>
puppet apply c:\modules\site.pp --modulepath c:/modules
</pre>

Puppet corrupts the file while copying it from the local file server:

<pre>
err: /Stage[main]/Splunk/Package[splunk]/ensure: change from absent to present 
failed: Execution of 'msiexec.exe /qn /no
restart /i c:\packages\splunk-4.2.4-110225-x64-release.msi 
INSTALLDIR=C:\splunk' returned 1620: T h i s   i n s t a l l
a t i o n   p a c k a g e   c o u l d   n o t   b e   o p e n e d .     C o n t 
a c t   t h e   a p p l i c a t i o n
v e n d o r   t o   v e r i f y   t h a t   t h i s   i s   a   v a l i d   W i 
n d o w s   I n s t a l l e r   p a c k
a g e .
</pre>


-- 
You have received this notification because you have either subscribed to it, 
or are involved in it.
To change your notification preferences, please click here: 
http://projects.puppetlabs.com/my/account

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Bugs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/puppet-bugs?hl=en.

Reply via email to