Changeset 9fcb32ca8058384a4bb91d748fcbd1f81378734d
- Timestamp:
- 08/10/08 16:45:18
(3 months ago)
- Author:
- Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
- git-committer:
- Giuseppe Bilotta <giuseppe.bilotta@gmail.com> 1218372318 +0200
- git-parent:
[e4f33c1ea92b56b09c6e58514c73b9a65bf09922]
- git-author:
- Giuseppe Bilotta <giuseppe.bilotta@gmail.com> 1218372131 +0200
- Message:
irclog core module: rename old logs when switching from dir to file
It may happen that a user changes from an irclog.filename_format where
some components are files to a format where they are directories (e.g.
from '%%{where}' to '%%{where}/%Y') or conversely. In this case, we
rename the existing file/dir by appending '.old.atime' to it (atime is
the actual file/dir access time).
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| re4f33c1 |
r9fcb32c |
|
| 274 | 274 | fp = logfilepath(where_str, now) |
|---|
| 275 | 275 | begin |
|---|
| 276 | | FileUtils.mkdir_p File.dirname(fp) |
|---|
| | 276 | dir = File.dirname(fp) |
|---|
| | 277 | # first of all, we check we're not trying to build a directory structure |
|---|
| | 278 | # where one of the components exists already as a file, so we |
|---|
| | 279 | # backtrack along dir until we come across the topmost existing name. |
|---|
| | 280 | # If it's a file, we rename to filename.old.filedate |
|---|
| | 281 | up = dir.dup |
|---|
| | 282 | until File.exist? up |
|---|
| | 283 | up.replace File.dirname up |
|---|
| | 284 | end |
|---|
| | 285 | unless File.directory? up |
|---|
| | 286 | backup = up.dup |
|---|
| | 287 | backup << ".old." << File.atime(up).strftime('%Y%m%d%H%M%S') |
|---|
| | 288 | debug "#{up} is not a directory! renaming to #{backup}" |
|---|
| | 289 | File.rename(up, backup) |
|---|
| | 290 | end |
|---|
| | 291 | FileUtils.mkdir_p(dir) |
|---|
| | 292 | # conversely, it may happen that fp exists and is a directory, in |
|---|
| | 293 | # which case we rename the directory instead |
|---|
| | 294 | if File.directory? fp |
|---|
| | 295 | backup = fp.dup |
|---|
| | 296 | backup << ".old." << File.atime(fp).strftime('%Y%m%d%H%M%S') |
|---|
| | 297 | debug "#{fp} is not a file! renaming to #{backup}" |
|---|
| | 298 | File.rename(fp, backup) |
|---|
| | 299 | end |
|---|
| | 300 | # it should be fine to create the file now |
|---|
| 277 | 301 | f = File.new(fp, "a") |
|---|
| 278 | 302 | f.sync = true |
|---|