Skip to content

Commit

Permalink
Filestore: Fail cleanly when adding symlinks with daemon running.
Browse files Browse the repository at this point in the history
Before adding a symlink could crash the daemon.

License: MIT
Signed-off-by: Kevin Atkinson <[email protected]>
  • Loading branch information
kevina committed Sep 16, 2016
1 parent 15e6ec7 commit 6857aec
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 1 deletion.
4 changes: 3 additions & 1 deletion core/commands/filestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,9 @@ func (f *fixPath) NextFile() (files.File, error) {
path := f.paths[0]
f.paths = f.paths[1:]
if f0.IsDirectory() {
return nil, errors.New("online directory add not supported, try '-S'")
return nil, fmt.Errorf("online directory add not supported, try '-S': %s", path)
} else if _, ok := f0.(*files.MultipartFile) ; !ok {
return nil, fmt.Errorf("online adding of special files not supported, try '-S': %s", path)
} else {
f, err := os.Open(path)
if err != nil {
Expand Down
83 changes: 83 additions & 0 deletions test/sharness/lib/test-filestore-lib.sh
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,74 @@ filestore_test_exact_paths() {
'
}

test_add_symlinks() {
opt=$1

test_expect_success "creating files with symbolic links succeeds" '
rm -rf files &&
mkdir -p files/foo &&
mkdir -p files/bar &&
echo "some text" > files/foo/baz &&
ln -s files/foo/baz files/bar/baz &&
ln -s files/does/not/exist files/bad
'

test_expect_success "adding a symlink adds the link itself" '
ipfs filestore add --logical -q $opt files/bar/baz > goodlink_out
'

test_expect_success "output looks good" '
echo "QmdocmZeF7qwPT9Z8SiVhMSyKA2KKoA2J7jToW6z6WBmxR" > goodlink_exp &&
test_cmp goodlink_exp goodlink_out
'

test_expect_success "adding a broken symlink works" '
ipfs filestore add --logical -q $opt files/bad > badlink_out
'

test_expect_success "output looks good" '
echo "QmWYN8SEXCgNT2PSjB6BnxAx6NJQtazWoBkTRH9GRfPFFQ" > badlink_exp &&
test_cmp badlink_exp badlink_out
'
}

test_add_symlinks_fails_cleanly() {
opt=$1

test_expect_success "creating files with symbolic links succeeds" '
rm -rf files &&
mkdir -p files/foo &&
mkdir -p files/bar &&
echo "some text" > files/foo/baz &&
ln -s files/foo/baz files/bar/baz &&
ln -s files/does/not/exist files/bad
'

test_expect_success "adding a symlink fails cleanly" '
test_must_fail ipfs filestore add --logical -q $opt files/bar/baz > goodlink_out
'

test_expect_success "ipfs daemon did not crash" '
kill -0 $IPFS_PID
'

test_expect_success "adding a broken link fails cleanly" '
test_must_fail ipfs filestore add --logical -q $opt files/bad > badlink_out
'

test_expect_success "ipfs daemon did not crash" '
kill -0 $IPFS_PID
'
}

test_add_dir_w_symlinks() {
opt=$1

test_expect_success "adding directory with symlinks in it works" '
ipfs filestore add --logical -q -r $opt files/ > dirlink_out
'
}

filestore_test_w_daemon() {
opt=$1

Expand Down Expand Up @@ -277,6 +345,17 @@ filestore_test_w_daemon() {

test_add_mulpl_files "filestore add "

test_expect_success "testing filestore add -r should fail" '
mkdir adir &&
echo "Hello Worlds!" > adir/file1 &&
echo "HELLO WORLDS!" > adir/file2 &&
random 5242880 41 > adir/file3 &&
test_must_fail ipfs filestore add -r "`pwd`/adir"
'
rm -rf adir

test_add_symlinks_fails_cleanly

filestore_test_exact_paths

test_expect_success "ipfs add -S fails unless enable" '
Expand Down Expand Up @@ -340,6 +419,10 @@ EOF

filestore_test_exact_paths '-S'

test_add_symlinks '-S'

test_add_dir_w_symlinks '-S'

test_kill_ipfs_daemon

}
4 changes: 4 additions & 0 deletions test/sharness/t0260-filestore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,10 @@ test_expect_success "testing filestore mv result" '
# Additional add tests
#

test_add_symlinks

test_add_dir_w_symlinks

test_add_cat_200MB "filestore add" "`pwd`"

test_done

0 comments on commit 6857aec

Please sign in to comment.