diff --git a/src/s3ql/_sqlite3ext.cpp b/src/s3ql/_sqlite3ext.cpp index ef61f7ee..7fb9245e 100644 --- a/src/s3ql/_sqlite3ext.cpp +++ b/src/s3ql/_sqlite3ext.cpp @@ -129,8 +129,14 @@ static int vfstraceWrite( if (!p->block_map) { return rc; } + + size_t end_off = iOfst + iAmt; + size_t max_blockno = end_off / blocksize; + if (max_blockno * blocksize < end_off) { + max_blockno++; + } for (size_t blockno = iOfst / blocksize; - blockno <= (iOfst + iAmt) / blocksize; + blockno < max_blockno; blockno++) { p->block_map->insert(blockno); } diff --git a/tests/t1_database.py b/tests/t1_database.py index 7f957b9e..0616f979 100755 --- a/tests/t1_database.py +++ b/tests/t1_database.py @@ -16,6 +16,8 @@ import logging +import math +import os import tempfile from argparse import Namespace from typing import List @@ -66,6 +68,20 @@ def test_track_dirty(): db.close() +def test_track_dirty_count(): + sqlite3ext.reset() + with tempfile.NamedTemporaryFile() as tmpfh: + db = Connection(tmpfh.name, BLOCKSIZE) + db.execute("CREATE TABLE foo (id INT);") + db.execute("INSERT INTO FOO VALUES(42)") + + db.checkpoint() + db_size = tmpfh.seek(0, os.SEEK_END) + assert db.dirty_blocks.get_count() == math.ceil(db_size / BLOCKSIZE) + + db.close() + + @pytest.fixture def backend(): with tempfile.TemporaryDirectory(prefix="s3ql-backend-") as backend_dir: