From 7c25ba0ad96ebbd1b1313677c5efc89f8226cea4 Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Fri, 29 Sep 2023 19:07:25 -0400 Subject: [PATCH] fix: don't combine journal files. #1605 --- CHANGES.rst | 6 ++++++ CONTRIBUTORS.txt | 1 + coverage/data.py | 5 +++++ tests/test_data.py | 3 +++ 4 files changed, 15 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 1d24f502e..92e8571d5 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -24,6 +24,12 @@ Unreleased ``[report] exclude_also`` settings (`issue 1684`_). This is now fixed, thanks `Jacqueline Lee `_. +- Sometimes SQLite will create journal files alongside the coverage.py database + files. These are ephemeral, but could be mistakenly included when combining + data files. Now they are always ignored, fixing `issue 1605`_. Thanks to + Brad Smith for suggesting fixes and providing detailed debugging. + +.. _issue 1605: https://github.com/nedbat/coveragepy/pull/1605 .. _issue 1684: https://github.com/nedbat/coveragepy/issues/1684 .. _pull 1685: https://github.com/nedbat/coveragepy/pull/1685 diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index 3493236e8..0f630deeb 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -31,6 +31,7 @@ Benjamin Parzella Benjamin Schubert Bernát Gábor Bill Hart +Brad Smith Bradley Burns Brandon Rhodes Brett Cannon diff --git a/coverage/data.py b/coverage/data.py index c196ac7ab..0868173b6 100644 --- a/coverage/data.py +++ b/coverage/data.py @@ -83,6 +83,11 @@ def combinable_files(data_file: str, data_paths: Optional[Iterable[str]] = None) files_to_combine.extend(glob.glob(pattern)) else: raise NoDataError(f"Couldn't combine from non-existent path '{p}'") + + # SQLite might have made journal files alongside our database files. + # We never want to combine those. + files_to_combine = [fnm for fnm in files_to_combine if not fnm.endswith("-journal")] + return files_to_combine diff --git a/tests/test_data.py b/tests/test_data.py index 7f23468cd..a90615a2f 100644 --- a/tests/test_data.py +++ b/tests/test_data.py @@ -887,6 +887,9 @@ def test_combining_from_files(self) -> None: covdata1.add_lines(LINES_1) covdata1.write() + # Journal files should never be included in the combining. + self.make_file("cov1/.coverage.1-journal", "xyzzy") + os.makedirs('cov2') covdata2 = DebugCoverageData('cov2/.coverage.2') covdata2.add_lines(LINES_2)