packages/s3ql: correctly determine buffer length when pre-seeked

This commit is contained in:
Max Headroom 2024-06-07 23:31:30 +02:00
parent d5c85b6a7c
commit b680f81e69

View file

@ -0,0 +1,26 @@
commit 1edbbcf08d5701ea38f13fca7491418318aebca9
Author: Max <max@privatevoid.net>
Date: Fri Jun 7 23:31:08 2024 +0200
accurate length
diff --git a/src/s3ql/backends/s3c.py b/src/s3ql/backends/s3c.py
index 2995ca4f..3c3c79ab 100644
--- a/src/s3ql/backends/s3c.py
+++ b/src/s3ql/backends/s3c.py
@@ -387,9 +387,13 @@ class Backend(AbstractBackend):
'''
off = fh.tell()
+ fh.seek(0, os.SEEK_END)
+ actual_len = fh.tell() - off
+ fh.seek(off, os.SEEK_SET)
if len_ is None:
- fh.seek(0, os.SEEK_END)
- len_ = fh.tell()
+ len_ = actual_len
+ else:
+ len_ = min(len_, actual_len)
return self._write_fh(key, fh, off, len_, metadata or {})
@retry