JRuby

JRuby File.rename() behavior different from Ruby, causes log rotation issue

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: JRuby 1.1b1
  • Fix Version/s: JRuby 1.1RC1
  • Component/s: Core Classes/Modules
  • Labels:
    None
  • Environment:
    Windows XP SP2, JRuby 1.1b1, Mongrel 1.1.1
    Ruby IRB using ruby 1.8.6 (2007-03-13 patchlevel 0) [i386-mswin32]
  • Number of attachments :
    2

Description

During a file rename operation, when the destination file exist, Ruby will overwrite the destination file with the source.
With JRuby, both files are untouched. As a result, the log rotation fails (no rotation occurs) after the maximum number of logs have reached, since it depends on the rename to overwrite the existing log files (Line 556 of lib/ruby/1.8/logger.rb).

The 2 IRB sessions below shows the problem.

Ruby IRB:
irb(main):001:0> File.open('test1.txt', 'w') { |file| file.write('test1') }
=> 5
irb(main):002:0> File.open('test2.txt', 'w') { |file| file.write('test2') }
=> 5
irb(main):003:0> File.read('test2.txt')
=> "test2"
irb(main):004:0> File.rename('test1.txt', 'test2.txt')
=> 0
irb(main):005:0> File.read('test2.txt')
=> "test1"
irb(main):006:0> File.read('test1.txt')
Errno::ENOENT: No such file or directory - test1.txt
from (irb):6:in `read'
from (irb):6
from :0
irb(main):007:0>

JRuby jIRB:
irb(main):001:0> File.open('test1.txt', 'w') { |file| file.write('test1') }
=> 5
irb(main):002:0> File.open('test2.txt', 'w') { |file| file.write('test2') }
=> 5
irb(main):003:0> File.read('test2.txt')
=> "test2"
irb(main):004:0> File.rename('test1.txt', 'test2.txt')
=> 0
irb(main):005:0> File.read('test2.txt') # Expecting "test1"
=> "test2"
irb(main):006:0> File.read('test1.txt') # Expecting error
=> "test1"
irb(main):007:0>

Activity

Hide
Vladimir Sizikov added a comment -

Simple file rename test attached.

Show
Vladimir Sizikov added a comment - Simple file rename test attached.
Hide
Vladimir Sizikov added a comment -

The problem is indeed reproducible on Windows.

Run the attached file_rename_test.rb, and you'll see:

MRI:

  1. ruby file_rename_test.rb
    test2
    0
    test1
    file_rename_test.rb:7:in `read': No such file or directory - test1.txt (Errno::ENOENT)
    from file_rename_test.rb:7

JRuby:

  1. jruby.bat file_rename.rb
    test2
    0
    test2
    test1

So, JRuby failed to rename the file, and failed to notify the user about it.

The proposed patch fixes the problem.

Show
Vladimir Sizikov added a comment - The problem is indeed reproducible on Windows. Run the attached file_rename_test.rb, and you'll see: MRI:
  1. ruby file_rename_test.rb test2 0 test1 file_rename_test.rb:7:in `read': No such file or directory - test1.txt (Errno::ENOENT) from file_rename_test.rb:7
JRuby:
  1. jruby.bat file_rename.rb test2 0 test2 test1
So, JRuby failed to rename the file, and failed to notify the user about it. The proposed patch fixes the problem.
Hide
Vladimir Sizikov added a comment -

Patch to fix this bug. Use patch -p1 to apply!

After this patch, JRuby on Windows behaves the same as MRI.

Show
Vladimir Sizikov added a comment - Patch to fix this bug. Use patch -p1 to apply! After this patch, JRuby on Windows behaves the same as MRI.
Hide
Thomas E Enebo added a comment -

Fixed on trunk in commit 5285 (patch by Vladimir Sizikov)

Show
Thomas E Enebo added a comment - Fixed on trunk in commit 5285 (patch by Vladimir Sizikov)

People

Vote (1)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: