diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2024-08-08 06:48:11 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-08-08 06:48:11 (GMT) |
commit | 6094c6fc2fc30eb9ee7c2f9f1088a851f71bf1b9 (patch) | |
tree | 745ed794e806f3dbfaba15dba97a7278ac9fb37b /Lib/logging | |
parent | 3f76b6b8ac706be46de0b23c3fd582ec4bd176d5 (diff) | |
download | cpython-6094c6fc2fc30eb9ee7c2f9f1088a851f71bf1b9.zip cpython-6094c6fc2fc30eb9ee7c2f9f1088a851f71bf1b9.tar.gz cpython-6094c6fc2fc30eb9ee7c2f9f1088a851f71bf1b9.tar.bz2 |
gh-116263: Do not rollover empty files in RotatingFileHandler (GH-122788)
Diffstat (limited to 'Lib/logging')
-rw-r--r-- | Lib/logging/handlers.py | 7 |
1 files changed, 5 insertions, 2 deletions
diff --git a/Lib/logging/handlers.py b/Lib/logging/handlers.py index 0fa40f5..1cba64f 100644 --- a/Lib/logging/handlers.py +++ b/Lib/logging/handlers.py @@ -196,9 +196,12 @@ class RotatingFileHandler(BaseRotatingHandler): if self.stream is None: # delay was set... self.stream = self._open() if self.maxBytes > 0: # are we rolling over? + pos = self.stream.tell() + if not pos: + # gh-116263: Never rollover an empty file + return False msg = "%s\n" % self.format(record) - self.stream.seek(0, 2) #due to non-posix-compliant Windows feature - if self.stream.tell() + len(msg) >= self.maxBytes: + if pos + len(msg) >= self.maxBytes: # See bpo-45401: Never rollover anything other than regular files if os.path.exists(self.baseFilename) and not os.path.isfile(self.baseFilename): return False |