2009
11.30

If you are using FileUtils, note the following behavior with ruby 1.9: attributes are not preserved by default when copying a file.

Consider the following script:

require 'fileutils'

MY_FILE = "/tmp/foo"
MY_FILE2 = "/tmp/foo2"

FileUtils.touch MY_FILE
FileUtils.chmod 0755, MY_FILE
puts (File.executable? MY_FILE)
FileUtils.cp MY_FILE, MY_FILE2
puts (File.executable? MY_FILE2)

With ruby 1.8.6:

~ > /usr/local/bin/ruby -v
ruby 1.8.6 (2007-03-13 patchlevel 0) [x86_64-linux]
~ > /usr/local/bin/ruby fileutils_chmodx.rb
true
true

With ruby 1.8.9:

~ > ruby -v
ruby 1.9.1p243 (2009-07-16 revision 24175) [x86_64-linux]
~ > ruby fileutils_chmodx.rb
true
false

Originally reported upstream here, the default behavior in ruby 1.9 will be to open files with the umask instead of preserving the attributes by default (see diff here). Use :preserve => true argument to override this behavior.

Share and Enjoy:
  • Twitter
  • Facebook
  • StumbleUpon
  • Google Bookmarks
  • LinkedIn
  • email
  • Slashdot
  • Digg
  • Netvibes
  • del.icio.us
  • HackerNews

No Comment.

Add Your Comment