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

                 Key: JRUBY-1672
                 URL: http://jira.codehaus.org/browse/JRUBY-1672
             Project: JRuby
          Issue Type: Bug
          Components: Core Classes/Modules
    Affects Versions: JRuby 1.1b1
         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]
            Reporter: Ka Yick Chua
            Priority: Minor


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>


-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://jira.codehaus.org/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply via email to