# HG changeset patch # User Matt Harbison # Date 1608830626 18000 # Node ID 9ea6b75b4a95f9f98aed6c895bb92a80f6e824e9 # Parent 9306a16ca96439123f5a34381cd74378d62f95f0 tests: demonstrate a case where a corrupt tag cache causes an abort I happened to hit this trying to cover other cases around valid vs missing entries. I have no idea if this is something that could occur more naturally (similar to how a missing file node in `hgtagsfnodes1` can occur after a strip). There is a test just above this added in f5a7cf0adb12 mentioning it "overwrites the junk", though that tests truncation instead of actual garbage. But since this is just a cache, it probably shouldn't abort with a cryptic message like this. The two options I see both have downsides- either rebuild the cache (and potentially take a long time), or hint to the user to run a debug command. Differential Revision: https://phab.mercurial-scm.org/D9812 diff -r 9306a16ca964 -r 9ea6b75b4a95 tests/test-tags.t --- a/tests/test-tags.t Tue Feb 16 20:38:14 2021 +0530 +++ b/tests/test-tags.t Thu Dec 24 12:23:46 2020 -0500 @@ -417,6 +417,49 @@ tip 5:8dbfe60eff30 bar 1:78391a272241 +BUG: If the filenode part of an entry in hgtagsfnodes is corrupt and +tags2-visible is missing, `hg tags` aborts. Corrupting the leading 4 bytes of +node hash (as above) doesn't seem to trigger the issue. Also note that the +debug command hides the corruption, both with and without tags2-visible. + + $ mv .hg/cache/hgtagsfnodes1 .hg/cache/hgtagsfnodes1.bak + $ hg debugupdatecaches + + >>> import os + >>> with open(".hg/cache/hgtagsfnodes1", "rb+") as fp: + ... fp.seek(-16, os.SEEK_END) and None + ... fp.write(b'\xde\xad') and None + + $ f --size --hexdump .hg/cache/hgtagsfnodes1 + .hg/cache/hgtagsfnodes1: size=144 + 0000: bb d1 79 df 00 00 00 00 00 00 00 00 00 00 00 00 |..y.............| + 0010: 00 00 00 00 00 00 00 00 78 39 1a 27 0c 04 f2 a8 |........x9.'....| + 0020: af 31 de 17 fa b7 42 28 78 ee 5a 2d ad bc 94 3d |.1....B(x.Z-...=| + 0030: 7a 94 12 77 0c 04 f2 a8 af 31 de 17 fa b7 42 28 |z..w.....1....B(| + 0040: 78 ee 5a 2d ad bc 94 3d 6f a4 50 21 7d 3b 71 8c |x.Z-...=o.P!};q.| + 0050: 96 4e f3 7b 89 e5 50 eb da fd 57 89 e7 6c e1 b0 |.N.{..P...W..l..| + 0060: 0c 19 2d 7d 0c 04 f2 a8 af 31 de 17 fa b7 42 28 |..-}.....1....B(| + 0070: 78 ee 5a 2d ad bc 94 3d 8d bf e6 0e 0c 04 f2 a8 |x.Z-...=........| + 0080: de ad de 17 fa b7 42 28 78 ee 5a 2d ad bc 94 3d |......B(x.Z-...=| + + $ hg debugtagscache | tail -2 + 4 0c192d7d5e6b78a714de54a2e9627952a877e25a 0c04f2a8af31de17fab7422878ee5a2dadbc943d + 5 8dbfe60eff306a54259cfe007db9e330e7ecf866 0c04f2a8deadde17fab7422878ee5a2dadbc943d + + $ rm -f .hg/cache/tags2-visible + $ hg debugtagscache | tail -2 + 4 0c192d7d5e6b78a714de54a2e9627952a877e25a 0c04f2a8af31de17fab7422878ee5a2dadbc943d + 5 8dbfe60eff306a54259cfe007db9e330e7ecf866 0c04f2a8deadde17fab7422878ee5a2dadbc943d + + $ hg tags + abort: data/.hgtags.i@0c04f2a8deadde17fab7422878ee5a2dadbc943d: no match found + [50] + +BUG: Unless this file is restored, the `hg tags` in the next unix-permissions +conditional will fail: "abort: data/.hgtags.i@0c04f2a8dead: no match found" + + $ mv .hg/cache/hgtagsfnodes1.bak .hg/cache/hgtagsfnodes1 + #if unix-permissions no-root Errors writing to .hgtags fnodes cache are silently ignored