Skip to content

Commit

Permalink
Resolve symlink if it is directly referenced in cli (#2897)
Browse files Browse the repository at this point in the history
* Resolve symlink if it is directly referenced in cli

test: Directly referenced symlink should be resolved

License: MIT
Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>

* sharness: add test for symlink in the middle

License: MIT
Signed-off-by: Jakub Sztandera <kubuxu@protonmail.ch>
  • Loading branch information
Kubuxu authored and whyrusleeping committed Jun 28, 2016
1 parent d72c9fc commit fe7b01f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
5 changes: 4 additions & 1 deletion commands/cli/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -388,7 +388,10 @@ func appendFile(fpath string, argDef *cmds.Argument, recursive, hidden bool) (fi
}

fpath = filepath.ToSlash(filepath.Clean(fpath))

fpath, err := filepath.EvalSymlinks(fpath)
if err != nil {
return nil, err
}
stat, err := os.Lstat(fpath)
if err != nil {
return nil, err
Expand Down
23 changes: 17 additions & 6 deletions test/sharness/t0044-add-symlink.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ test_description="Test add -w"
test_expect_success "creating files succeeds" '
mkdir -p files/foo &&
mkdir -p files/bar &&
mkdir -p files/badin
echo "some text" > files/foo/baz &&
ln -s files/foo/baz files/bar/baz &&
ln -s files/does/not/exist files/bad
ln -s ../foo/baz files/bar/baz &&
ln -s files/does/not/exist files/badin/bad &&
mkdir -p files2/a/b/c &&
echo "some other text" > files2/a/b/c/foo &&
ln -s b files2/a/d
'

test_add_symlinks() {
Expand All @@ -23,27 +27,34 @@ test_add_symlinks() {
'

test_expect_success "output looks good" '
echo QmWdiHKoeSW8G1u7ATCgpx4yMoUhYaJBQGkyPLkS9goYZ8 > filehash_exp &&
echo QmQRgZT6xVFKJLVVpJDu3WcPkw2iqQ1jqK1F9jmdeq9zAv > filehash_exp &&
test_cmp filehash_exp filehash_out
'

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

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

test_expect_success "adding a broken symlink works" '
ipfs add -q files/bad > badlink_out
ipfs add -qr files/badin | head -1 > badlink_out
'

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

test_expect_success "adding with symlink in middle of path is same as\
adding with no symlink" '
ipfs add -rq files2/a/b/c > no_sym &&
ipfs add -rq files2/a/d/c > sym &&
test_cmp no_sym sym
'
}

test_init_ipfs
Expand Down

0 comments on commit fe7b01f

Please sign in to comment.