From f710b31ff4a289fa8efeb3c4c23c4cf0c55a7d4a Mon Sep 17 00:00:00 2001 From: Lucas Molas Date: Wed, 28 Feb 2018 10:29:18 -0300 Subject: [PATCH] unixfs: clean path in DagArchive Fixes #4720. License: MIT Signed-off-by: Lucas Molas --- test/sharness/t0090-get.sh | 8 ++++++++ unixfs/archive/archive.go | 3 ++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/test/sharness/t0090-get.sh b/test/sharness/t0090-get.sh index 12e23819c29..8e85ae8b8e5 100755 --- a/test/sharness/t0090-get.sh +++ b/test/sharness/t0090-get.sh @@ -104,6 +104,14 @@ test_get_cmd() { rm -r "$HASH2" ' + # Test issue #4720: problems when path contains a trailing slash. + test_expect_success "ipfs get with slash (directory)" ' + ipfs get "$HASH2/" && + test_cmp dir/a "$HASH2"/a && + test_cmp dir/b/c "$HASH2"/b/c && + rm -r "$HASH2" + ' + test_expect_success "ipfs get -a -C succeeds (directory)" ' ipfs get "$HASH2" -a -C >actual ' diff --git a/unixfs/archive/archive.go b/unixfs/archive/archive.go index 7a561992ef5..4aecb186f56 100644 --- a/unixfs/archive/archive.go +++ b/unixfs/archive/archive.go @@ -33,7 +33,8 @@ func (i *identityWriteCloser) Close() error { // DagArchive is equivalent to `ipfs getdag $hash | maybe_tar | maybe_gzip` func DagArchive(ctx context.Context, nd ipld.Node, name string, dag ipld.DAGService, archive bool, compression int) (io.Reader, error) { - _, filename := path.Split(name) + cleaned := path.Clean(name) + _, filename := path.Split(cleaned) // need to connect a writer to a reader piper, pipew := io.Pipe()