DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUGĀ·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=41735>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED ANDĀ·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=41735

           Summary: RollingFileAppender may delete files during rollover
           Product: Log4j
           Version: 1.2
          Platform: Other
        OS/Version: other
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Appender
        AssignedTo: [email protected]
        ReportedBy: [EMAIL PROTECTED]


The RollingFileAppender tries to rename the old files during roll over. 
However, it does not check if the rename succeeded and as a result, it may end
up deleting information.  In particular, on Windows, the file rename can fail if
another process has the file open.

This problem was found in 1.2.14 and seems to still exist in 1.2.15 rc1.

The following changes address the issue.
120a121,122
>     boolean failedRename = false;
> 
127,131c129,139
<     if(maxBackupIndex > 0) {
<       // Delete the oldest file, to keep Windows happy.
<       file = new File(fileName + '.' + maxBackupIndex);
<       if (file.exists())
<        file.delete();
---
>     // if the .1 file doesn't exist then we don't need to rename either
>     if ((maxBackupIndex > 0)) {
>       target = new File(fileName + "." + 1);
>       if (target.exists()) {
>        // Delete the oldest file, to keep Windows happy.
>        file = new File(fileName + '.' + maxBackupIndex);
>        if (file.exists()) {
>          if (! file.delete()) {
>             failedRename = true;
>          }
>        }
133,140c141,154
<       // Map {(maxBackupIndex - 1), ..., 2, 1} to {maxBackupIndex, ..., 3, 2}
<       for (int i = maxBackupIndex - 1; i >= 1; i--) {
<       file = new File(fileName + "." + i);
<       if (file.exists()) {
<         target = new File(fileName + '.' + (i + 1));
<         LogLog.debug("Renaming file " + file + " to " + target);
<         file.renameTo(target);
<       }
---
>        // Map {(maxBackupIndex - 1), ..., 2, 1} to {maxBackupIndex, ..., 3, 2}
>        if (! failedRename) {
>           for (int i = maxBackupIndex - 1; i >= 1; i--) {
>             file = new File(fileName + "." + i);
>             if (file.exists()) {
>               target = new File(fileName + '.' + (i + 1));
>               LogLog.debug("Renaming file " + file + " to " + target);
>               if (! file.renameTo(target)) {
>                  failedRename = true;
>                  break;
>               }
>             }

-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to