提交 a3bd2c23 作者: Kevin Atkinson

Add "--raw-leaves" option to "ipfs files"

License: MIT
Signed-off-by: 's avatarKevin Atkinson <k@kevina.org>
上级 7302c3ab
...@@ -43,6 +43,7 @@ operations. ...@@ -43,6 +43,7 @@ operations.
}, },
Options: []cmds.Option{ Options: []cmds.Option{
cmds.BoolOption("f", "flush", "Flush target and ancestors after write.").Default(true), cmds.BoolOption("f", "flush", "Flush target and ancestors after write.").Default(true),
cmds.BoolOption("raw-leaves", "Use raw blocks for newly created leaf nodes. (experimental)"),
}, },
Subcommands: map[string]*cmds.Command{ Subcommands: map[string]*cmds.Command{
"read": FilesReadCmd, "read": FilesReadCmd,
...@@ -598,6 +599,7 @@ stat' on the file or any of its ancestors. ...@@ -598,6 +599,7 @@ stat' on the file or any of its ancestors.
create, _, _ := req.Option("create").Bool() create, _, _ := req.Option("create").Bool()
trunc, _, _ := req.Option("truncate").Bool() trunc, _, _ := req.Option("truncate").Bool()
flush, _, _ := req.Option("flush").Bool() flush, _, _ := req.Option("flush").Bool()
rawLeaves, _, _ := req.Option("raw-leaves").Bool()
nd, err := req.InvocContext().GetNode() nd, err := req.InvocContext().GetNode()
if err != nil { if err != nil {
...@@ -620,6 +622,7 @@ stat' on the file or any of its ancestors. ...@@ -620,6 +622,7 @@ stat' on the file or any of its ancestors.
res.SetError(err, cmds.ErrNormal) res.SetError(err, cmds.ErrNormal)
return return
} }
fi.RawLeaves = rawLeaves
wfd, err := fi.Open(mfs.OpenWriteOnly, flush) wfd, err := fi.Open(mfs.OpenWriteOnly, flush)
if err != nil { if err != nil {
......
...@@ -23,6 +23,8 @@ type File struct { ...@@ -23,6 +23,8 @@ type File struct {
dserv dag.DAGService dserv dag.DAGService
node node.Node node node.Node
nodelk sync.Mutex nodelk sync.Mutex
RawLeaves bool
} }
// NewFile returns a NewFile object with the given parameters // NewFile returns a NewFile object with the given parameters
...@@ -79,6 +81,7 @@ func (fi *File) Open(flags int, sync bool) (FileDescriptor, error) { ...@@ -79,6 +81,7 @@ func (fi *File) Open(flags int, sync bool) (FileDescriptor, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
dmod.RawLeaves = fi.RawLeaves
return &fileDescriptor{ return &fileDescriptor{
inode: fi, inode: fi,
......
...@@ -89,114 +89,116 @@ test_sharding() { ...@@ -89,114 +89,116 @@ test_sharding() {
} }
test_files_api() { test_files_api() {
ROOT_HASH=$1 local EXTRA ARGS
EXTRA=$1
ARGS=$2
test_expect_success "can mkdir in root" ' test_expect_success "can mkdir in root $EXTRA" '
ipfs files mkdir /cats ipfs files $ARGS mkdir /cats
' '
test_expect_success "'files ls' lists root by default" ' test_expect_success "'files ls' lists root by default $EXTRA" '
ipfs files ls >actual && ipfs files $ARGS ls >actual &&
echo "cats" >expected && echo "cats" >expected &&
test_cmp expected actual test_cmp expected actual
' '
test_expect_success "directory was created" ' test_expect_success "directory was created $EXTRA" '
verify_path_exists /cats verify_path_exists /cats
' '
test_expect_success "directory is empty" ' test_expect_success "directory is empty $EXTRA" '
verify_dir_contents /cats verify_dir_contents /cats
' '
# we do verification of stat formatting now as we depend on it # we do verification of stat formatting now as we depend on it
test_expect_success "stat works" ' test_expect_success "stat works $EXTRA" '
ipfs files stat / >stat ipfs files $ARGS stat / >stat
' '
test_expect_success "hash is first line of stat" ' test_expect_success "hash is first line of stat $EXTRA" '
ipfs ls $(head -1 stat) | grep "cats" ipfs ls $(head -1 stat) | grep "cats"
' '
test_expect_success "stat --hash gives only hash" ' test_expect_success "stat --hash gives only hash $EXTRA" '
ipfs files stat --hash / >actual && ipfs files $ARGS stat --hash / >actual &&
head -n1 stat >expected && head -n1 stat >expected &&
test_cmp expected actual test_cmp expected actual
' '
test_expect_success "stat with multiple format options should fail" ' test_expect_success "stat with multiple format options should fail $EXTRA" '
test_must_fail ipfs files stat --hash --size / test_must_fail ipfs files $ARGS stat --hash --size /
' '
test_expect_success "compare hash option with format" ' test_expect_success "compare hash option with format $EXTRA" '
ipfs files stat --hash / >expected && ipfs files $ARGS stat --hash / >expected &&
ipfs files stat --format='"'"'<hash>'"'"' / >actual && ipfs files $ARGS stat --format='"'"'<hash>'"'"' / >actual &&
test_cmp expected actual test_cmp expected actual
' '
test_expect_success "compare size option with format" ' test_expect_success "compare size option with format $EXTRA" '
ipfs files stat --size / >expected && ipfs files $ARGS stat --size / >expected &&
ipfs files stat --format='"'"'<cumulsize>'"'"' / >actual && ipfs files $ARGS stat --format='"'"'<cumulsize>'"'"' / >actual &&
test_cmp expected actual test_cmp expected actual
' '
test_expect_success "check root hash" ' test_expect_success "check root hash $EXTRA" '
ipfs files stat --hash / > roothash ipfs files $ARGS stat --hash / > roothash
' '
test_expect_success "cannot mkdir /" ' test_expect_success "cannot mkdir / $EXTRA" '
test_expect_code 1 ipfs files mkdir / test_expect_code 1 ipfs files $ARGS mkdir /
' '
test_expect_success "check root hash was not changed" ' test_expect_success "check root hash was not changed $EXTRA" '
ipfs files stat --hash / > roothashafter && ipfs files $ARGS stat --hash / > roothashafter &&
test_cmp roothash roothashafter test_cmp roothash roothashafter
' '
test_expect_success "can put files into directory" ' test_expect_success "can put files into directory $EXTRA" '
ipfs files cp /ipfs/$FILE1 /cats/file1 ipfs files $ARGS cp /ipfs/$FILE1 /cats/file1
' '
test_expect_success "file shows up in directory" ' test_expect_success "file shows up in directory $EXTRA" '
verify_dir_contents /cats file1 verify_dir_contents /cats file1
' '
test_expect_success "file has correct hash and size in directory" ' test_expect_success "file has correct hash and size in directory $EXTRA" '
echo "file1 $FILE1 4" > ls_l_expected && echo "file1 $FILE1 4" > ls_l_expected &&
ipfs files ls -l /cats > ls_l_actual && ipfs files $ARGS ls -l /cats > ls_l_actual &&
test_cmp ls_l_expected ls_l_actual test_cmp ls_l_expected ls_l_actual
' '
test_expect_success "can read file" ' test_expect_success "can read file $EXTRA" '
ipfs files read /cats/file1 > file1out ipfs files $ARGS read /cats/file1 > file1out
' '
test_expect_success "output looks good" ' test_expect_success "output looks good $EXTRA" '
echo foo > expected && echo foo > expected &&
test_cmp expected file1out test_cmp expected file1out
' '
test_expect_success "can put another file into root" ' test_expect_success "can put another file into root $EXTRA" '
ipfs files cp /ipfs/$FILE2 /file2 ipfs files $ARGS cp /ipfs/$FILE2 /file2
' '
test_expect_success "file shows up in root" ' test_expect_success "file shows up in root $EXTRA" '
verify_dir_contents / file2 cats verify_dir_contents / file2 cats
' '
test_expect_success "can read file" ' test_expect_success "can read file $EXTRA" '
ipfs files read /file2 > file2out ipfs files $ARGS read /file2 > file2out
' '
test_expect_success "output looks good" ' test_expect_success "output looks good $EXTRA" '
echo bar > expected && echo bar > expected &&
test_cmp expected file2out test_cmp expected file2out
' '
test_expect_success "can make deep directory" ' test_expect_success "can make deep directory $EXTRA" '
ipfs files mkdir -p /cats/this/is/a/dir ipfs files $ARGS mkdir -p /cats/this/is/a/dir
' '
test_expect_success "directory was created correctly" ' test_expect_success "directory was created correctly $EXTRA" '
verify_path_exists /cats/this/is/a/dir && verify_path_exists /cats/this/is/a/dir &&
verify_dir_contents /cats this file1 && verify_dir_contents /cats this file1 &&
verify_dir_contents /cats/this is && verify_dir_contents /cats/this is &&
...@@ -205,362 +207,378 @@ test_files_api() { ...@@ -205,362 +207,378 @@ test_files_api() {
verify_dir_contents /cats/this/is/a/dir verify_dir_contents /cats/this/is/a/dir
' '
test_expect_success "can copy file into new dir" ' test_expect_success "can copy file into new dir $EXTRA" '
ipfs files cp /ipfs/$FILE3 /cats/this/is/a/dir/file3 ipfs files $ARGS cp /ipfs/$FILE3 /cats/this/is/a/dir/file3
' '
test_expect_success "can read file" ' test_expect_success "can read file $EXTRA" '
ipfs files read /cats/this/is/a/dir/file3 > output ipfs files $ARGS read /cats/this/is/a/dir/file3 > output
' '
test_expect_success "output looks good" ' test_expect_success "output looks good $EXTRA" '
echo baz > expected && echo baz > expected &&
test_cmp expected output test_cmp expected output
' '
test_expect_success "file shows up in dir" ' test_expect_success "file shows up in dir $EXTRA" '
verify_dir_contents /cats/this/is/a/dir file3 verify_dir_contents /cats/this/is/a/dir file3
' '
test_expect_success "can remove file" ' test_expect_success "can remove file $EXTRA" '
ipfs files rm /cats/this/is/a/dir/file3 ipfs files $ARGS rm /cats/this/is/a/dir/file3
' '
test_expect_success "file no longer appears" ' test_expect_success "file no longer appears $EXTRA" '
verify_dir_contents /cats/this/is/a/dir verify_dir_contents /cats/this/is/a/dir
' '
test_expect_success "can remove dir" ' test_expect_success "can remove dir $EXTRA" '
ipfs files rm -r /cats/this/is/a/dir ipfs files $ARGS rm -r /cats/this/is/a/dir
' '
test_expect_success "dir no longer appears" ' test_expect_success "dir no longer appears $EXTRA" '
verify_dir_contents /cats/this/is/a verify_dir_contents /cats/this/is/a
' '
test_expect_success "can remove file from root" ' test_expect_success "can remove file from root $EXTRA" '
ipfs files rm /file2 ipfs files $ARGS rm /file2
' '
test_expect_success "file no longer appears" ' test_expect_success "file no longer appears $EXTRA" '
verify_dir_contents / cats verify_dir_contents / cats
' '
test_expect_success "check root hash" ' test_expect_success "check root hash $EXTRA" '
ipfs files stat --hash / > roothash ipfs files $ARGS stat --hash / > roothash
' '
test_expect_success "cannot remove root" ' test_expect_success "cannot remove root $EXTRA" '
test_expect_code 1 ipfs files rm -r / test_expect_code 1 ipfs files $ARGS rm -r /
' '
test_expect_success "check root hash was not changed" ' test_expect_success "check root hash was not changed $EXTRA" '
ipfs files stat --hash / > roothashafter && ipfs files $ARGS stat --hash / > roothashafter &&
test_cmp roothash roothashafter test_cmp roothash roothashafter
' '
# test read options # test read options
test_expect_success "read from offset works" ' test_expect_success "read from offset works $EXTRA" '
ipfs files read -o 1 /cats/file1 > output ipfs files $ARGS read -o 1 /cats/file1 > output
' '
test_expect_success "output looks good" ' test_expect_success "output looks good $EXTRA" '
echo oo > expected && echo oo > expected &&
test_cmp expected output test_cmp expected output
' '
test_expect_success "read with size works" ' test_expect_success "read with size works $EXTRA" '
ipfs files read -n 2 /cats/file1 > output ipfs files $ARGS read -n 2 /cats/file1 > output
' '
test_expect_success "output looks good" ' test_expect_success "output looks good $EXTRA" '
printf fo > expected && printf fo > expected &&
test_cmp expected output test_cmp expected output
' '
test_expect_success "cannot read from negative offset" ' test_expect_success "cannot read from negative offset $EXTRA" '
test_expect_code 1 ipfs files read --offset -3 /cats/file1 test_expect_code 1 ipfs files $ARGS read --offset -3 /cats/file1
' '
test_expect_success "read from offset 0 works" ' test_expect_success "read from offset 0 works $EXTRA" '
ipfs files read --offset 0 /cats/file1 > output ipfs files $ARGS read --offset 0 /cats/file1 > output
' '
test_expect_success "output looks good" ' test_expect_success "output looks good $EXTRA" '
echo foo > expected && echo foo > expected &&
test_cmp expected output test_cmp expected output
' '
test_expect_success "read last byte works" ' test_expect_success "read last byte works $EXTRA" '
ipfs files read --offset 2 /cats/file1 > output ipfs files $ARGS read --offset 2 /cats/file1 > output
' '
test_expect_success "output looks good" ' test_expect_success "output looks good $EXTRA" '
echo o > expected && echo o > expected &&
test_cmp expected output test_cmp expected output
' '
test_expect_success "offset past end of file fails" ' test_expect_success "offset past end of file fails $EXTRA" '
test_expect_code 1 ipfs files read --offset 5 /cats/file1 test_expect_code 1 ipfs files $ARGS read --offset 5 /cats/file1
' '
test_expect_success "cannot read negative count bytes" ' test_expect_success "cannot read negative count bytes $EXTRA" '
test_expect_code 1 ipfs read --count -1 /cats/file1 test_expect_code 1 ipfs read --count -1 /cats/file1
' '
test_expect_success "reading zero bytes prints nothing" ' test_expect_success "reading zero bytes prints nothing $EXTRA" '
ipfs files read --count 0 /cats/file1 > output ipfs files $ARGS read --count 0 /cats/file1 > output
' '
test_expect_success "output looks good" ' test_expect_success "output looks good $EXTRA" '
printf "" > expected && printf "" > expected &&
test_cmp expected output test_cmp expected output
' '
test_expect_success "count > len(file) prints entire file" ' test_expect_success "count > len(file) prints entire file $EXTRA" '
ipfs files read --count 200 /cats/file1 > output ipfs files $ARGS read --count 200 /cats/file1 > output
' '
test_expect_success "output looks good" ' test_expect_success "output looks good $EXTRA" '
echo foo > expected && echo foo > expected &&
test_cmp expected output test_cmp expected output
' '
# test write # test write
test_expect_success "can write file" ' test_expect_success "can write file $EXTRA" '
echo "ipfs rocks" > tmpfile && echo "ipfs rocks" > tmpfile &&
cat tmpfile | ipfs files write --create /cats/ipfs cat tmpfile | ipfs files $ARGS write --create /cats/ipfs
' '
test_expect_success "file was created" ' test_expect_success "file was created $EXTRA" '
verify_dir_contents /cats ipfs file1 this verify_dir_contents /cats ipfs file1 this
' '
test_expect_success "can read file we just wrote" ' test_expect_success "can read file we just wrote $EXTRA" '
ipfs files read /cats/ipfs > output ipfs files $ARGS read /cats/ipfs > output
' '
test_expect_success "can write to offset" ' test_expect_success "can write to offset $EXTRA" '
echo "is super cool" | ipfs files write -o 5 /cats/ipfs echo "is super cool" | ipfs files $ARGS write -o 5 /cats/ipfs
' '
test_expect_success "file looks correct" ' test_expect_success "file looks correct $EXTRA" '
echo "ipfs is super cool" > expected && echo "ipfs is super cool" > expected &&
ipfs files read /cats/ipfs > output && ipfs files $ARGS read /cats/ipfs > output &&
test_cmp expected output test_cmp expected output
' '
test_expect_success "cant write to negative offset" ' test_expect_success "file hash correct $EXTRA" '
ipfs files stat --hash /cats/ipfs > filehash && echo $FILE_HASH > filehash_expected &&
test_expect_code 1 ipfs files write --offset -1 /cats/ipfs < output ipfs files $ARGS stat --hash /cats/ipfs > filehash &&
test_cmp filehash_expected filehash
' '
test_expect_success "verify file was not changed" ' test_expect_success "cant write to negative offset $EXTRA" '
ipfs files stat --hash /cats/ipfs > afterhash && test_expect_code 1 ipfs files $ARGS write --offset -1 /cats/ipfs < output
'
test_expect_success "verify file was not changed $EXTRA" '
ipfs files $ARGS stat --hash /cats/ipfs > afterhash &&
test_cmp filehash afterhash test_cmp filehash afterhash
' '
test_expect_success "write new file for testing" ' test_expect_success "write new file for testing $EXTRA" '
echo foobar | ipfs files write --create /fun echo foobar | ipfs files $ARGS write --create /fun
' '
test_expect_success "write to offset past end works" ' test_expect_success "write to offset past end works $EXTRA" '
echo blah | ipfs files write --offset 50 /fun echo blah | ipfs files $ARGS write --offset 50 /fun
' '
test_expect_success "can read file" ' test_expect_success "can read file $EXTRA" '
ipfs files read /fun > sparse_output ipfs files $ARGS read /fun > sparse_output
' '
test_expect_success "output looks good" ' test_expect_success "output looks good $EXTRA" '
echo foobar > sparse_expected && echo foobar > sparse_expected &&
echo blah | dd of=sparse_expected bs=50 seek=1 && echo blah | dd of=sparse_expected bs=50 seek=1 &&
test_cmp sparse_expected sparse_output test_cmp sparse_expected sparse_output
' '
test_expect_success "cleanup" ' test_expect_success "cleanup $EXTRA" '
ipfs files rm /fun ipfs files $ARGS rm /fun
' '
test_expect_success "cannot write to directory" ' test_expect_success "cannot write to directory $EXTRA" '
ipfs files stat --hash /cats > dirhash && ipfs files $ARGS stat --hash /cats > dirhash &&
test_expect_code 1 ipfs files write /cats < output test_expect_code 1 ipfs files $ARGS write /cats < output
' '
test_expect_success "verify dir was not changed" ' test_expect_success "verify dir was not changed $EXTRA" '
ipfs files stat --hash /cats > afterdirhash && ipfs files $ARGS stat --hash /cats > afterdirhash &&
test_cmp dirhash afterdirhash test_cmp dirhash afterdirhash
' '
test_expect_success "cannot write to nonexistant path" ' test_expect_success "cannot write to nonexistant path $EXTRA" '
test_expect_code 1 ipfs files write /cats/bar/ < output test_expect_code 1 ipfs files $ARGS write /cats/bar/ < output
' '
test_expect_success "no new paths were created" ' test_expect_success "no new paths were created $EXTRA" '
verify_dir_contents /cats file1 ipfs this verify_dir_contents /cats file1 ipfs this
' '
test_expect_success "write 'no-flush' succeeds" ' test_expect_success "write 'no-flush' succeeds $EXTRA" '
echo "testing" | ipfs files write -f=false -e /cats/walrus echo "testing" | ipfs files $ARGS write -f=false -e /cats/walrus
' '
test_expect_success "root hash not bubbled up yet" ' test_expect_success "root hash not bubbled up yet $EXTRA" '
test -z "$ONLINE" || test -z "$ONLINE" ||
(ipfs refs local > refsout && (ipfs refs local > refsout &&
test_expect_code 1 grep $ROOT_HASH refsout) test_expect_code 1 grep $ROOT_HASH refsout)
' '
test_expect_success "changes bubbled up to root on inspection" ' test_expect_success "changes bubbled up to root on inspection $EXTRA" '
ipfs files stat --hash / > root_hash ipfs files $ARGS stat --hash / > root_hash
' '
test_expect_success "root hash looks good" ' test_expect_success "root hash looks good $EXTRA" '
export EXP_ROOT_HASH="$ROOT_HASH" && export EXP_ROOT_HASH="$ROOT_HASH" &&
echo $EXP_ROOT_HASH > root_hash_exp && echo $EXP_ROOT_HASH > root_hash_exp &&
test_cmp root_hash_exp root_hash test_cmp root_hash_exp root_hash
' '
test_expect_success "flush root succeeds" ' test_expect_success "flush root succeeds $EXTRA" '
ipfs files flush / ipfs files $ARGS flush /
' '
# test mv # test mv
test_expect_success "can mv dir" ' test_expect_success "can mv dir $EXTRA" '
ipfs files mv /cats/this/is /cats/ ipfs files $ARGS mv /cats/this/is /cats/
' '
test_expect_success "mv worked" ' test_expect_success "mv worked $EXTRA" '
verify_dir_contents /cats file1 ipfs this is walrus && verify_dir_contents /cats file1 ipfs this is walrus &&
verify_dir_contents /cats/this verify_dir_contents /cats/this
' '
test_expect_success "cleanup, remove 'cats'" ' test_expect_success "cleanup, remove 'cats' $EXTRA" '
ipfs files rm -r /cats ipfs files $ARGS rm -r /cats
' '
test_expect_success "cleanup looks good" ' test_expect_success "cleanup looks good $EXTRA" '
verify_dir_contents / verify_dir_contents /
' '
# test truncating # test truncating
test_expect_success "create a new file" ' test_expect_success "create a new file $EXTRA" '
echo "some content" | ipfs files write --create /cats echo "some content" | ipfs files $ARGS write --create /cats
' '
test_expect_success "truncate and write over that file" ' test_expect_success "truncate and write over that file $EXTRA" '
echo "fish" | ipfs files write --truncate /cats echo "fish" | ipfs files $ARGS write --truncate /cats
' '
test_expect_success "output looks good" ' test_expect_success "output looks good $EXTRA" '
ipfs files read /cats > file_out && ipfs files $ARGS read /cats > file_out &&
echo "fish" > file_exp && echo "fish" > file_exp &&
test_cmp file_out file_exp test_cmp file_out file_exp
' '
test_expect_success "cleanup" ' test_expect_success "cleanup $EXTRA" '
ipfs files rm /cats ipfs files $ARGS rm /cats
' '
# test flush flags # test flush flags
test_expect_success "mkdir --flush works" ' test_expect_success "mkdir --flush works $EXTRA" '
ipfs files mkdir --flush --parents /flushed/deep ipfs files $ARGS mkdir --flush --parents /flushed/deep
' '
test_expect_success "mkdir --flush works a second time" ' test_expect_success "mkdir --flush works a second time $EXTRA" '
ipfs files mkdir --flush --parents /flushed/deep ipfs files $ARGS mkdir --flush --parents /flushed/deep
' '
test_expect_success "dir looks right" ' test_expect_success "dir looks right $EXTRA" '
verify_dir_contents / flushed verify_dir_contents / flushed
' '
test_expect_success "child dir looks right" ' test_expect_success "child dir looks right $EXTRA" '
verify_dir_contents /flushed deep verify_dir_contents /flushed deep
' '
test_expect_success "cleanup" ' test_expect_success "cleanup $EXTRA" '
ipfs files rm -r /flushed ipfs files $ARGS rm -r /flushed
' '
test_expect_success "child dir looks right" ' test_expect_success "child dir looks right $EXTRA" '
verify_dir_contents / verify_dir_contents /
' '
# test for https://github.com/ipfs/go-ipfs/issues/2654 # test for https://github.com/ipfs/go-ipfs/issues/2654
test_expect_success "create and remove dir" ' test_expect_success "create and remove dir $EXTRA" '
ipfs files mkdir /test_dir && ipfs files $ARGS mkdir /test_dir &&
ipfs files rm -r "/test_dir" ipfs files $ARGS rm -r "/test_dir"
' '
test_expect_success "create test file" ' test_expect_success "create test file $EXTRA" '
echo "content" | ipfs files write -e "/test_file" echo "content" | ipfs files $ARGS write -e "/test_file"
' '
test_expect_success "copy test file onto test dir" ' test_expect_success "copy test file onto test dir $EXTRA" '
ipfs files cp "/test_file" "/test_dir" ipfs files $ARGS cp "/test_file" "/test_dir"
' '
test_expect_success "test /test_dir" ' test_expect_success "test /test_dir $EXTRA" '
ipfs files stat "/test_dir" | grep -q "^Type: file" ipfs files $ARGS stat "/test_dir" | grep -q "^Type: file"
' '
test_expect_success "clean up /test_dir and /test_file" ' test_expect_success "clean up /test_dir and /test_file $EXTRA" '
ipfs files rm -r /test_dir && ipfs files $ARGS rm -r /test_dir &&
ipfs files rm -r /test_file ipfs files $ARGS rm -r /test_file
' '
test_expect_success "make a directory and a file" ' test_expect_success "make a directory and a file $EXTRA" '
ipfs files mkdir /adir && ipfs files $ARGS mkdir /adir &&
echo "blah" | ipfs files write --create /foobar echo "blah" | ipfs files $ARGS write --create /foobar
' '
test_expect_success "copy a file into a directory" ' test_expect_success "copy a file into a directory $EXTRA" '
ipfs files cp /foobar /adir/ ipfs files $ARGS cp /foobar /adir/
' '
test_expect_success "file made it into directory" ' test_expect_success "file made it into directory $EXTRA" '
ipfs files ls /adir | grep foobar ipfs files $ARGS ls /adir | grep foobar
' '
test_expect_success "clean up" ' test_expect_success "clean up $EXTRA" '
ipfs files rm -r /foobar && ipfs files $ARGS rm -r /foobar &&
ipfs files rm -r /adir ipfs files $ARGS rm -r /adir
' '
test_expect_success "root mfs entry is empty" ' test_expect_success "root mfs entry is empty $EXTRA" '
verify_dir_contents / verify_dir_contents /
' '
test_expect_success "repo gc" ' test_expect_success "repo gc $EXTRA" '
ipfs repo gc ipfs repo gc
' '
} }
# test offline and online # test offline and online
test_expect_success "can create some files for testing" '
create_files
'
test_files_api QmcwKfTMCT7AaeiD92hWjnZn9b6eh9NxnhfSzN5x2vnDpt
test_expect_success "can create some files for testing with raw-leaves" ' tests_for_files_api() {
create_files --raw-leaves local EXTRA
' EXTRA=$1
test_files_api QmTpKiKcAj4sbeesN6vrs5w3QeVmd4QmGpxRL81hHut4dZ
test_expect_success "can create some files for testing ($extra)" '
create_files
'
ROOT_HASH=QmcwKfTMCT7AaeiD92hWjnZn9b6eh9NxnhfSzN5x2vnDpt
FILE_HASH=QmQdQt9qooenjeaNhiKHF3hBvmNteB4MQBtgu3jxgf9c7i
test_files_api "($EXTRA)"
test_expect_success "can create some files for testing with raw-leaves ($extra)" '
create_files --raw-leaves
'
ROOT_HASH=QmTpKiKcAj4sbeesN6vrs5w3QeVmd4QmGpxRL81hHut4dZ
test_files_api "($EXTRA, partial raw-leaves)"
test_expect_success "can create some files for testing with raw-leaves ($extra)" '
create_files --raw-leaves
'
ROOT_HASH=QmW3dMSU6VNd1mEdpk9S3ZYRuR1YwwoXjGaZhkyK6ru9YU
FILE_HASH=QmRCgHeoKxCqK2Es6M6nPUDVWz19yNQPnsXGsXeuTkSKpN
test_files_api "($EXTRA, raw-leaves)" --raw-leaves
}
tests_for_files_api "online"
test_launch_ipfs_daemon --offline test_launch_ipfs_daemon --offline
ONLINE=1 # set online flag so tests can easily tell ONLINE=1 # set online flag so tests can easily tell
test_expect_success "can create some files for testing" '
create_files
'
test_files_api QmcwKfTMCT7AaeiD92hWjnZn9b6eh9NxnhfSzN5x2vnDpt
test_expect_success "can create some files for testing with raw-leaves" ' tests_for_files_api "offline"
create_files --raw-leaves
'
test_files_api QmTpKiKcAj4sbeesN6vrs5w3QeVmd4QmGpxRL81hHut4dZ
test_kill_ipfs_daemon --offline test_kill_ipfs_daemon --offline
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论