Sync with 'master'
[alt-git.git] / t / lib-chunk.sh
blob9f01df190bb116bd593d8b9ecf94bc4fd4144f38
1 # Shell library for working with "chunk" files (commit-graph, midx, etc).
3 # corrupt_chunk_file <fn> <chunk> <offset> <bytes>
5 # Corrupt a chunk-based file (like a commit-graph) by overwriting the bytes
6 # found in the chunk specified by the 4-byte <chunk> identifier. If <offset> is
7 # "clear", replace the chunk entirely. Otherwise, overwrite data <offset> bytes
8 # into the chunk.
10 # The <bytes> are interpreted as pairs of hex digits (so "000000FE" would be
11 # big-endian 254).
12 corrupt_chunk_file () {
13 fn=$1; shift
14 perl "$TEST_DIRECTORY"/lib-chunk/corrupt-chunk-file.pl \
15 "$@" <"$fn" >"$fn.tmp" &&
16 # some vintages of macOS 'mv' fails to overwrite a read-only file.
17 mv -f "$fn.tmp" "$fn"