Fixing locking; unlock still not working

This commit is contained in:
Ben Johnson
2020-11-03 16:35:58 -07:00
parent b1ec5c721b
commit e52d3be78d
4 changed files with 88 additions and 34 deletions

View File

@@ -2,7 +2,9 @@ package litestream
import (
"encoding/binary"
"encoding/hex"
"io"
"strings"
)
// Magic number specified at the beginning of WAL files.
@@ -40,3 +42,38 @@ func Checksum(bo binary.ByteOrder, s uint64, b []byte) (_ uint64, err error) {
}
return uint64(s0)<<32 | uint64(s1), nil
}
// HexDump returns hexdump output but with duplicate lines removed.
func HexDump(b []byte) string {
const prefixN = len("00000000")
var output []string
var prev string
var ellipsis bool
lines := strings.Split(strings.TrimSpace(hex.Dump(b)), "\n")
for i, line := range lines {
// Add line to output if it is not repeating or the last line.
if i == 0 || i == len(lines)-1 || trimPrefixN(line, prefixN) != trimPrefixN(prev, prefixN) {
output = append(output, line)
prev, ellipsis = line, false
continue
}
// Add an ellipsis for the first duplicate line.
if !ellipsis {
output = append(output, "...")
ellipsis = true
continue
}
}
return strings.Join(output, "\n")
}
func trimPrefixN(s string, n int) string {
if len(s) < n {
return ""
}
return s[n:]
}