The Puppet Labs Issue Tracker has Moved: https://tickets.puppetlabs.com

This issue tracker is now in read-only archive mode and automatic ticket export has been disabled. Redmine users will need to create a new JIRA account to file tickets using https://tickets.puppetlabs.com. See the following page for information on filing tickets with JIRA:

Bug #21285

Facter.processorcount fails on Windows 64bit

Added by Maurizio De Santis almost 3 years ago. Updated almost 3 years ago.

Status:Merged - Pending ReleaseStart date:
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:windows
Target version:-
Keywords:windows Affected Facter version:1.7.1
Branch:

We've Moved!

Ticket tracking is now hosted in JIRA: https://tickets.puppetlabs.com


Description

I’m running facter 1.7.1, Ruby 64bit 2.0.0-p195 via RubyInstaller on Windows 7 64bit; running Facter.fact(:processorcount) I get this error:

irb(main):002:0> Facter.fact(:processorcount)
Encoding::CompatibilityError: path name must be ASCII-compatible (UTF-16LE): "C:\\ProgramData"
        from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/facter-1.7.1/lib/facter/util/config.rb:37:in `join'
        from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/facter-1.7.1/lib/facter/util/config.rb:37:in `external_facts_dirs'
        from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/facter-1.7.1/lib/facter/util/directory_loader.rb:46:in `default_loader'
        from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/facter-1.7.1/lib/facter/util/config.rb:8:in `ext_fact_loader'
        from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/facter-1.7.1/lib/facter.rb:56:in `collection'
        from C:/Ruby200-x64/lib/ruby/gems/2.0.0/gems/facter-1.7.1/lib/facter.rb:112:in `block (2 levels) in singleton class'
        from (irb):2
        from C:/Ruby200-x64/bin/irb:12:in `
'

It works modifing Facter::Util::Config.windows_data_dir as follows:

  def self.windows_data_dir
    if Dir.const_defined? 'COMMON_APPDATA' then
      Dir::COMMON_APPDATA.encode('ASCII')
    else
      nil
    end
  end

Related issues

Related to Puppet - Bug #17010: win32-dir gem returns a string whose encoding is not `asc... Closed

History

#1 Updated by Josh Cooper almost 3 years ago

  • Description updated (diff)
  • Status changed from Unreviewed to Needs More Information

This is the same issue as #17010, but is now showing up in Facter. For some reason ruby expects file paths to be ascii_compatible? (see https://bugs.ruby-lang.org/issues/7168), and the win32-dir gem returns a UTF-16LE encoded string (wchar_t *). I don’t understand why ruby requires that, but whatever, we tried…

Can you see if the issue is resolved for you in ruby193 (and is now broken again in ruby 2.0)? Or if it’s broken consistently in ruby193 and 2.0? Also, can you include the output of:

C:\>wmic os get codeset, locale, oslanguage

#2 Updated by Josh Cooper almost 3 years ago

  • Keywords set to windows

#3 Updated by Maurizio De Santis almost 3 years ago

Using 1.9.3 I get another error:

>ruby -rfacter -e 'puts Facter.processorcount'
C:/Ruby193/lib/ruby/gems/1.9.1/gems/facter-1.7.1/lib/facter/util/config.rb:37:i
 `join': string contains null byte (ArgumentError)
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/facter-1.7.1/lib/facter/util/c
nfig.rb:37:in `external_facts_dirs'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/facter-1.7.1/lib/facter/util/d
rectory_loader.rb:46:in `default_loader'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/facter-1.7.1/lib/facter/util/c
nfig.rb:8:in `ext_fact_loader'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/facter-1.7.1/lib/facter.rb:56:
n `collection'
        from C:/Ruby193/lib/ruby/gems/1.9.1/gems/facter-1.7.1/lib/facter.rb:150
in `method_missing'
        from -e:1:in `
'

But it gets solved with the same solution ( Dir::COMMON_APPDATA.encode(‘ASCII’) )

#4 Updated by Josh Cooper almost 3 years ago

Thanks Maurizio. Ruby 1.8 doesn’t really understand encodings, and since UTF-16LE results in a null byte for each ASCII character, it’s getting confused. Could you run the wmic command and include your output in the ticket?

#5 Updated by Maurizio De Santis almost 3 years ago

This is the output of the wmic command:

>wmic os get codeset, locale, oslanguage
CodeSet  Locale  OSLanguage
1252     0410    1040

#6 Updated by Josh Cooper almost 3 years ago

  • Status changed from Needs More Information to Accepted

Thanks Maurizio, this is the same issue #17010, just in facter.

#7 Updated by Josh Cooper almost 3 years ago

Submitted PR upstream https://github.com/djberg96/win32-dir/pull/3. Once that’s merged, we’ll need to update the respective Gemfiles for puppet, facter, and hiera.

#8 Updated by Josh Cooper almost 3 years ago

PR has been merged into the ffi branch, but new version is not yet released. Once gem is released, next steps are to add it to the puppet-win32-ruby repo, and update the license, because win32-dir 0.4.x will add a new dependency on ffi which is LGPLv3.

#9 Updated by Josh Cooper almost 3 years ago

Interestingly, I get different results when run via ruby and bundler (on fr_FR):

C:\work\facter>ruby -S facter --trace
c:/work/facter/lib/facter/util/config.rb:38:in `join': string contains null byte (ArgumentError)
        from c:/work/facter/lib/facter/util/config.rb:38:in `external_facts_dirs'
        from c:/work/facter/lib/facter/util/directory_loader.rb:46:in `default_loader'
        from c:/work/facter/lib/facter/util/config.rb:8:in `ext_fact_loader'
        from c:/work/facter/lib/facter.rb:65:in `collection'
        from c:/work/facter/lib/facter.rb:186:in `to_hash'
        from c:/work/facter/lib/facter/application.rb:45:in `run'
        from c:/work/facter/bin/facter:74:in `<main>'
C:\work\facter>bundle exec facter hostname
WIN-616UKRQP00N

I presume bundler is changing the default encoding in some way, which is just awesome, because we use bundler for our spec tests…

#10 Updated by Josh Cooper almost 3 years ago

Josh Cooper wrote:

Interestingly, I get different results when run via ruby and bundler (on fr_FR):

My mistake, I get the same results with bundler and not. Here’s a simpler example:

C:\work\win32-dir>type Gemfile
source "https://rubygems.org"

gem 'win32-dir', :path => File.expand_path("..", __FILE__)
gem 'ffi'

C:\work\win32-dir>bundle install
Resolving dependencies...
Using ffi (1.9.0)
Using win32-dir (0.4.2) from source at .
Using bundler (1.3.5)
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.

C:\work\win32-dir>bundle exec ruby -e "require 'win32/dir'; puts Dir::COMMON_APPDATA.encoding"
UTF-16LE

And

C:\work\win32-dir>set RUBYLIB=c:\work\win32-dir\lib

C:\work\win32-dir> ruby -e "require 'win32/dir'; puts Dir::COMMON_APPDATA.encoding"
UTF-16LE

In any case, a new gem should be out today: https://github.com/djberg96/win32-dir/pull/4#issuecomment-21488150

#11 Updated by Josh Cooper almost 3 years ago

  • Status changed from Accepted to In Topic Branch Pending Review

I’ve submitted a PR to https://github.com/puppetlabs/puppet-win32-ruby/pull/10 which adds the latest win32-dir gem to our MSI. This will be released with the next puppet release 3.2.4 or 3.3.0, whichever comes first.

Alternatively, you can do gem install win32-dir to grab the latest version (which requires ruby 1.9).

#12 Updated by Matthaus Owens almost 3 years ago

  • Status changed from In Topic Branch Pending Review to Merged - Pending Release

#13 Updated by Josh Cooper almost 3 years ago

This will be fixed in puppet 3.2.4 or 3.3.0, which ever comes first as the win32-dir gem has been updated to 0.4.3. Alternatively, you can do a gem update win32-dir.

Also available in: Atom PDF