Commit aba06b81 authored by ale's avatar ale

Improve database restore I/O robustness

This fixes an awesome bug where restoring from a pipe would not work,
because that's the case where you're going to see short Read()s.
parent ce2898f6
Pipeline #464 passed with stages
in 1 minute and 23 seconds
......@@ -454,12 +454,21 @@ func writeBytes(w io.Writer, b []byte) error {
func readBytes(r io.Reader) ([]byte, error) {
var sz uint32
if err := binary.Read(r, binary.LittleEndian, &sz); err != nil {
var szb [4]byte
n, err := io.ReadFull(r, szb[:])
if err != nil {
return nil, err
if n != 4 {
return nil, errors.New("short header read")
sz := binary.LittleEndian.Uint32(szb[:])
b := make([]byte, sz)
_, err := r.Read(b)
n, err = io.ReadFull(r, b)
if n != int(sz) {
return nil, errors.New("short data read")
return b, err
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment