mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
gh-116263: Do not rollover empty files in RotatingFileHandler (GH-122788)
This commit is contained in:
parent
3f76b6b8ac
commit
6094c6fc2f
3 changed files with 58 additions and 5 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue