From ce671c9efc7b31ec2762d1598ff6cb551c0bc38b Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Thu, 12 Nov 2026 10:51:31 +0200 Subject: [PATCH] Recovered a license header cache damaged below its schema; pull requests restore the base branch cache by name --- .github/workflows/check-license-headers.yml | 2 +- .../license-headers/check_license_headers.py | 4 ++++ .../test_check_license_headers.py | 18 ++++++++++++++++++ 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check-license-headers.yml b/.github/workflows/check-license-headers.yml index d8cebb1815..66d7b295f2 100644 --- a/.github/workflows/check-license-headers.yml +++ b/.github/workflows/check-license-headers.yml @@ -54,7 +54,7 @@ jobs: path: target/license-headers-cache key: license-headers-ce-v1-${{ github.ref_name }}-${{ github.run_id }} restore-keys: | - license-headers-ce-v1-${{ github.ref_name }}- + license-headers-ce-v1-${{ github.base_ref || github.ref_name }}- license-headers-ce-v1- - name: Check license headers diff --git a/tools/src/main/python/license-headers/check_license_headers.py b/tools/src/main/python/license-headers/check_license_headers.py index ec520d9fb9..ec024f470d 100644 --- a/tools/src/main/python/license-headers/check_license_headers.py +++ b/tools/src/main/python/license-headers/check_license_headers.py @@ -936,6 +936,10 @@ class NormalizationCache: def open(self): database = sqlite3.connect(self.path, check_same_thread=False) database.execute("CREATE TABLE IF NOT EXISTS normalized (input TEXT PRIMARY KEY, content BLOB NOT NULL)") + # Opening reads only the schema: a file damaged below it would fail on the first lookup instead. + if database.execute("PRAGMA quick_check").fetchone()[0] != "ok": + database.close() + raise sqlite3.DatabaseError(f"{self.path} is damaged") return database @staticmethod diff --git a/tools/src/main/python/license-headers/test_check_license_headers.py b/tools/src/main/python/license-headers/test_check_license_headers.py index 0756cc41bd..7eb94b401c 100644 --- a/tools/src/main/python/license-headers/test_check_license_headers.py +++ b/tools/src/main/python/license-headers/test_check_license_headers.py @@ -1304,6 +1304,24 @@ class CacheTests(unittest.TestCase): self.assertEqual({("A.java", "a"): b"normalized"}, p.NormalizationCache(directory, "damaged").get({("A.java", "a"): b"raw"})) + def test_a_cache_damaged_after_its_schema_is_started_again(self): + directory = temporary_directory(self) + cache = p.NormalizationCache(directory, "damaged") + cache.put([((f"F{index}.java", "a"), f"raw {index}".encode(), b"normalized" * 400) for index in range(300)]) + cache.close() + database = directory / "damaged.sqlite" + page = 4096 + with database.open("r+b") as file: + # The schema and the root pages stay readable, so the file opens; every lookup below them fails. + file.seek(4 * page) + file.write(b"\xff" * (database.stat().st_size - 4 * page)) + cache = p.NormalizationCache(directory, "damaged") + self.assertEqual({}, cache.get({("F0.java", "a"): b"raw 0"})) + cache.put([(("A.java", "a"), b"raw", b"normalized")]) + cache.close() + self.assertEqual({("A.java", "a"): b"normalized"}, + p.NormalizationCache(directory, "damaged").get({("A.java", "a"): b"raw"})) + def test_the_cache_of_a_branch_checked_long_ago_survives_newer_signatures(self): directory = temporary_directory(self) p.NormalizationCache(directory, "revisited").close()