From 16dad7515b6e5b3d38051422bdb6de5aed0b613d Mon Sep 17 00:00:00 2001 From: Jakub Sztandera Date: Wed, 7 Mar 2018 23:26:54 +0100 Subject: [PATCH] tar: fix Go 1.10 breakage License: MIT Signed-off-by: Jakub Sztandera --- test/sharness/t0090-get.sh | 20 ++++++++++++++++++++ thirdparty/tar/extractor.go | 13 +++++++------ 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/test/sharness/t0090-get.sh b/test/sharness/t0090-get.sh index 12e23819c29..e8224a4816c 100755 --- a/test/sharness/t0090-get.sh +++ b/test/sharness/t0090-get.sh @@ -125,6 +125,26 @@ test_get_cmd() { test_must_fail ipfs get ../.. 2>actual && test_cmp expected actual ' + + test_expect_success "create small file" ' + echo "foo" > small && + ipfs add -q small > hash_small + ' + + test_expect_success "get small file" ' + ipfs get -o out_small $(cat hash_small) && + test_cmp small out_small + ' + + test_expect_success "create medium file" ' + head -c 16000 > medium && + ipfs add -q medium > hash_medium + ' + + test_expect_success "get medium file" ' + ipfs get -o out_medium $(cat hash_medium) && + test_cmp medium out_medium + ' } test_get_fail() { diff --git a/thirdparty/tar/extractor.go b/thirdparty/tar/extractor.go index b84926bb249..fddf8082eea 100644 --- a/thirdparty/tar/extractor.go +++ b/thirdparty/tar/extractor.go @@ -114,18 +114,19 @@ func copyWithProgress(to io.Writer, from io.Reader, cb func(int64) int64) error buf := make([]byte, 4096) for { n, err := from.Read(buf) + if n != 0 { + cb(int64(n)) + _, err2 := to.Write(buf[:n]) + if err2 != nil { + return err2 + } + } if err != nil { if err == io.EOF { return nil } return err } - - cb(int64(n)) - _, err = to.Write(buf[:n]) - if err != nil { - return err - } } }