darcs

Issue 2643 patch index may become corrupt

Title patch index may become corrupt
Priority bug Status resolved
Milestone Resolved in
Superseder Nosy List bfrk
Assigned To
Topics

Created on 2020-04-24.08:41:30 by bfrk, last changed 2022-04-12.13:35:49 by bfrk.

Messages
msg21992 (view) Author: bfrk Date: 2020-04-24.08:41:26
We recently observed a situation where darcs (2.14.2 or 2.12.5) failed
with the log command and a file name:

> darcs-2.14.2 log README.rst
darcs: not enough bytes
CallStack (from HasCallStack):
  error, called at libraries/binary/src/Data/Binary.hs:218:21 in
binary-0.8.3.0:Data.Binary

Searching for where the binary library is used in darcs leads one to the
patch index. In Darcs.Repository.PatchIndex we call
Data.Binary.decodeFile which throws an error when it cannot successfully
decode the file.

To verify this, I changed the code to call decodeFileOrFail and fail
with a more descriptive message. I made this change in the 2.14 branch
because in the development branch the format has been changed (due to
the FileName->AnchoredPath refactor), which means that the patch index
will be re-created from scratch whether it is corrupt or not.

Indeed, now I get

> darcs-2.14.3 log README.rst
darcs failed:  Patch index is corrupt (file
.../_darcs/patch_index/touch_map at offset 272129): not enough bytes

It is unclear what exactly has caused the patch index to become corrupt.
This may be a bug in darcs or it may have been accidentally done by the
user.

In any case, the error message should be further extended to contain a
recommendation how the user can fix the problem. The most straight
forward solution is to remove the corrupt file and try again:

> darcs-2.14.3 log README.rst

darcs failed:  Patch index is corrupt (file
.../_darcs/patch_index/touch_map at offset 272129): not enough bytes
Please remove the corrupt file and then try again.

Indeed, doing so fixed the patch index.

I will add this mitigation to the 2.14.3 release.
msg22383 (view) Author: bfrk Date: 2020-08-02.09:38:22
Renaming the ticket because the unhelpful error message has been fixed:

patch 82fe27cc6295a2e55936b3b1ff10fcb4966e1e5e
Author: Ben Franksen <ben.franksen@online.de>
Date:   Fri Apr 24 10:45:44 CEST 2020
  * mitigate issue2643 with a better error message
  
  If the patch index is corrupt, output the name of the currupt file and
  suggest its removal.
History
Date User Action Args
2020-04-24 08:41:30bfrkcreate
2020-08-02 09:38:25bfrksetmessages: + msg22383
title: patch index may become corrupt, error message not helpful -> patch index may become corrupt
2022-04-12 13:35:49bfrksetstatus: unknown -> resolved
priority: bug