From 13b067bad2d4a4a9f142badf01177992de8b79d9 Mon Sep 17 00:00:00 2001 From: gammazero <11790789+gammazero@users.noreply.github.com> Date: Wed, 14 Aug 2024 03:43:07 -0700 Subject: [PATCH] Add sharness tests for mode and mtime Update to kubo with rpc suport for symlinks Add tests for directory contents --- go.mod | 2 +- go.sum | 4 +- main.go | 23 +++--- sharness/dependencies/go.mod | 4 +- sharness/dependencies/go.sum | 4 +- sharness/t0040-unixfs-mode-modtime.sh | 105 ++++++++++++++++++++++++++ 6 files changed, 122 insertions(+), 20 deletions(-) create mode 100755 sharness/t0040-unixfs-mode-modtime.sh diff --git a/go.mod b/go.mod index 405b4d3..dcc5621 100644 --- a/go.mod +++ b/go.mod @@ -5,7 +5,7 @@ go 1.22 require ( github.com/cheggaaa/pb/v3 v3.1.4 github.com/ipfs/boxo v0.22.1-0.20240814075207-b27ba953ad58 - github.com/ipfs/kubo v0.29.1-0.20240814075518-8d75eb260aea + github.com/ipfs/kubo v0.29.1-0.20240816001438-d6c6999c6631 github.com/libp2p/go-libp2p v0.36.1 github.com/multiformats/go-multiaddr v0.13.0 github.com/urfave/cli/v2 v2.25.7 diff --git a/go.sum b/go.sum index e2b34cf..49c011b 100644 --- a/go.sum +++ b/go.sum @@ -368,8 +368,8 @@ github.com/ipfs/go-unixfsnode v1.9.0 h1:ubEhQhr22sPAKO2DNsyVBW7YB/zA8Zkif25aBvz8 github.com/ipfs/go-unixfsnode v1.9.0/go.mod h1:HxRu9HYHOjK6HUqFBAi++7DVoWAHn0o4v/nZ/VA+0g8= github.com/ipfs/go-verifcid v0.0.3 h1:gmRKccqhWDocCRkC+a59g5QW7uJw5bpX9HWBevXa0zs= github.com/ipfs/go-verifcid v0.0.3/go.mod h1:gcCtGniVzelKrbk9ooUSX/pM3xlH73fZZJDzQJRvOUw= -github.com/ipfs/kubo v0.29.1-0.20240814075518-8d75eb260aea h1:46yAF5MYeq6jj90HtvyVT8oxgg3gn6LQv1OW0yR9ZY4= -github.com/ipfs/kubo v0.29.1-0.20240814075518-8d75eb260aea/go.mod h1:QuWIeYvLkstvAslRHIt8UVCroP+ckMLVysh9gyH2kOg= +github.com/ipfs/kubo v0.29.1-0.20240816001438-d6c6999c6631 h1:AWUl8/A7Oc4nMGHyQ8R9xvkzX36tQSIur1pcJ/+UAo8= +github.com/ipfs/kubo v0.29.1-0.20240816001438-d6c6999c6631/go.mod h1:QuWIeYvLkstvAslRHIt8UVCroP+ckMLVysh9gyH2kOg= github.com/ipld/go-car v0.6.2 h1:Hlnl3Awgnq8icK+ze3iRghk805lu8YNq3wlREDTF2qc= github.com/ipld/go-car v0.6.2/go.mod h1:oEGXdwp6bmxJCZ+rARSkDliTeYnVzv3++eXajZ+Bmr8= github.com/ipld/go-car/v2 v2.13.1 h1:KnlrKvEPEzr5IZHKTXLAEub+tPrzeAFQVRlSQvuxBO4= diff --git a/main.go b/main.go index 4c6deec..b4ac284 100644 --- a/main.go +++ b/main.go @@ -171,25 +171,24 @@ func parsePath(path string) (ipath.Path, error) { if err == nil { return ipfsPath, nil } + origErr := err + + ipfsPath, err = ipath.NewPath("/ipfs/" + path) + if err == nil { + return ipfsPath, nil + } u, err := url.Parse(path) if err != nil { - return nil, fmt.Errorf("%q could not be parsed: %s", path, err) + return nil, origErr } - - proto := u.Scheme - switch proto { + switch u.Scheme { case "ipfs", "ipld", "ipns": - ipfsPath, err = ipath.NewPath(gopath.Join("/", proto, u.Host, u.Path)) + return ipath.NewPath(gopath.Join("/", u.Scheme, u.Host, u.Path)) case "http", "https": - ipfsPath, err = ipath.NewPath(u.Path) - default: - return nil, fmt.Errorf("%q is not recognized as an IPFS path", path) - } - if err != nil { - return nil, fmt.Errorf("cannot create %s path: %w", proto, err) + return ipath.NewPath(u.Path) } - return ipfsPath, nil + return nil, fmt.Errorf("%q is not recognized as an IPFS path", path) } // WriteTo writes the given node to the local filesystem at fpath. diff --git a/sharness/dependencies/go.mod b/sharness/dependencies/go.mod index f41aed8..67eb92a 100644 --- a/sharness/dependencies/go.mod +++ b/sharness/dependencies/go.mod @@ -2,12 +2,10 @@ module github.com/ipfs/ipget/sharness/dependencies go 1.22 -toolchain go1.22.5 - require ( github.com/chriscool/go-sleep v0.0.0-20150606204034-743ab5f1bb48 github.com/ipfs/ipget v0.9.2 - github.com/ipfs/kubo v0.29.1-0.20240814075518-8d75eb260aea + github.com/ipfs/kubo v0.29.1-0.20240816001438-d6c6999c6631 github.com/whyrusleeping/pollEndpoint v0.0.0-20211207235059-e4819e26509a ) diff --git a/sharness/dependencies/go.sum b/sharness/dependencies/go.sum index 36584d4..7a3c37a 100644 --- a/sharness/dependencies/go.sum +++ b/sharness/dependencies/go.sum @@ -437,8 +437,8 @@ github.com/ipfs/go-unixfsnode v1.9.0 h1:ubEhQhr22sPAKO2DNsyVBW7YB/zA8Zkif25aBvz8 github.com/ipfs/go-unixfsnode v1.9.0/go.mod h1:HxRu9HYHOjK6HUqFBAi++7DVoWAHn0o4v/nZ/VA+0g8= github.com/ipfs/go-verifcid v0.0.3 h1:gmRKccqhWDocCRkC+a59g5QW7uJw5bpX9HWBevXa0zs= github.com/ipfs/go-verifcid v0.0.3/go.mod h1:gcCtGniVzelKrbk9ooUSX/pM3xlH73fZZJDzQJRvOUw= -github.com/ipfs/kubo v0.29.1-0.20240814075518-8d75eb260aea h1:46yAF5MYeq6jj90HtvyVT8oxgg3gn6LQv1OW0yR9ZY4= -github.com/ipfs/kubo v0.29.1-0.20240814075518-8d75eb260aea/go.mod h1:QuWIeYvLkstvAslRHIt8UVCroP+ckMLVysh9gyH2kOg= +github.com/ipfs/kubo v0.29.1-0.20240816001438-d6c6999c6631 h1:AWUl8/A7Oc4nMGHyQ8R9xvkzX36tQSIur1pcJ/+UAo8= +github.com/ipfs/kubo v0.29.1-0.20240816001438-d6c6999c6631/go.mod h1:QuWIeYvLkstvAslRHIt8UVCroP+ckMLVysh9gyH2kOg= github.com/ipld/go-car v0.6.2 h1:Hlnl3Awgnq8icK+ze3iRghk805lu8YNq3wlREDTF2qc= github.com/ipld/go-car v0.6.2/go.mod h1:oEGXdwp6bmxJCZ+rARSkDliTeYnVzv3++eXajZ+Bmr8= github.com/ipld/go-car/v2 v2.13.1 h1:KnlrKvEPEzr5IZHKTXLAEub+tPrzeAFQVRlSQvuxBO4= diff --git a/sharness/t0040-unixfs-mode-modtime.sh b/sharness/t0040-unixfs-mode-modtime.sh new file mode 100755 index 0000000..9af0139 --- /dev/null +++ b/sharness/t0040-unixfs-mode-modtime.sh @@ -0,0 +1,105 @@ +#!/usr/bin/env bash + +test_description="test the ipget command setting unix mode and modification time" + + +. lib/test-lib.sh + +# start the local ipfs node +test_init_ipfs +test_launch_ipfs_daemon + +test_expect_success "create test file with mode and mtime" ' + echo "hello ipget" > test_file && + ipfs add -q --mode=0666 --mtime=660000000 test_file > hash + cat hash +' +test_expect_success "retrieve file with mode and mtime" ' + ipget -o data.txt --node=local "/ipfs/$( out && + echo "660000000 666" > expect && + test_cmp expect out + ;; + Darwin) + stat -f "%m %p" data.txt > out && + echo "660000000 100666" > expect && + test_cmp expect out + ;; + *) + echo "unsupported system: $(uname)" + esac +' + +test_expect_success "create a test directory" ' + mkdir test_dir && + cp test_file test_dir/data.txt && + ipfs add --mode=0777 --mtime=660000000 -rQ test_dir > dir_hash +' + +test_expect_success "retrieve a directory with mode and mtime" ' + ipget --node=local -o got_dir "/ipfs/$( out2 && + echo "660000000 777" > expect2 && + test_cmp expect2 out2 && + stat --format="%Y %a" got_dir/data.txt > out3 && + echo "660000000 100777" > expect3 && + test_cmp expect3 out3 + ;; + Darwin) + stat -f "%m %p" got_dir > out2 && + echo "660000000 40777" > expect2 && + test_cmp expect2 out2 && + stat -f "%m %p" got_dir/data.txt > out3 && + echo "660000000 100777" > expect3 && + test_cmp expect3 out3 + ;; + *) + echo "unsupported system: $(uname)" + esac +' + +test_expect_success "create a test directory with symlink" ' + case $(uname -s) in + Linux|FreeBSD|Darwin) + mkdir test_dir2 && + cp test_file test_dir2/data.txt && + ln -s test_file test_dir2/test_file_link && + touch -h -t 9011301320 test_dir2/test_file_link && + ipfs add --preserve-mtime -rQ test_dir2 > dir2_hash + ;; + *) + echo "unsupported system: $(uname)" + esac +' + +test_expect_success "retrieve a directory with symlink with mode and mtime" ' + case $(uname -s) in + Linux|FreeBSD) + ipget --node=local -o got_dir2 "/ipfs/$( link_target && + echo "test_file" > expect_target && + test_cmp expect_target link_target && + stat --format="%Y" got_dir2/test_file_link > out4 && + echo "660000000" > expect4 && + test_cmp expect4 out4 + ;; + Darwin) + ipget --node=local -o got_dir2 "/ipfs/$( link_target && + echo "test_file" > expect_target && + test_cmp expect_target link_target + ;; + *) + echo "unsupported system: $(uname)" + esac +' + +# kill the local ipfs node +test_kill_ipfs_daemon + +test_done