@cryptotaxi247 / kubo / commits / fe7b01f14

Resolve symlink if it is directly referenced in cli (#2897)

* 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>

Jakub Sztandera committed Jun 28, 2016 at 21:06 UTC fe7b01f14e2b8db6e856b567dbd7db4d00f6e366
2 files changed +21 -7
commands/cli/parse.go
+4 -1
@@ -388,7 +388,10 @@ func appendFile(fpath string, argDef *cmds.Argument, recursive, hidden bool) (fi
388 }
389
390 fpath = filepath.ToSlash(filepath.Clean(fpath))
391 -
391 + fpath, err := filepath.EvalSymlinks(fpath)
392 + if err != nil {
393 + return nil, err
394 + }
395 stat, err := os.Lstat(fpath)
396 if err != nil {
397 return nil, err
test/sharness/t0044-add-symlink.sh
+17 -6
@@ -11,9 +11,13 @@ test_description="Test add -w"
11 test_expect_success "creating files succeeds" '
12 mkdir -p files/foo &&
13 mkdir -p files/bar &&
14 + mkdir -p files/badin
15 echo "some text" > files/foo/baz &&
15 - ln -s files/foo/baz files/bar/baz &&
16 - ln -s files/does/not/exist files/bad
16 + ln -s ../foo/baz files/bar/baz &&
17 + ln -s files/does/not/exist files/badin/bad &&
18 + mkdir -p files2/a/b/c &&
19 + echo "some other text" > files2/a/b/c/foo &&
20 + ln -s b files2/a/d
21 '
22
23 test_add_symlinks() {
@@ -23,27 +27,34 @@ test_add_symlinks() {
27 '
28
29 test_expect_success "output looks good" '
26 - echo QmWdiHKoeSW8G1u7ATCgpx4yMoUhYaJBQGkyPLkS9goYZ8 > filehash_exp &&
30 + echo QmQRgZT6xVFKJLVVpJDu3WcPkw2iqQ1jqK1F9jmdeq9zAv > filehash_exp &&
31 test_cmp filehash_exp filehash_out
32 '
33
30 - test_expect_success "adding a symlink adds the link itself" '
34 + test_expect_success "adding a symlink adds the file itself" '
35 ipfs add -q files/bar/baz > goodlink_out
36 '
37
38 test_expect_success "output looks good" '
35 - echo "QmdocmZeF7qwPT9Z8SiVhMSyKA2KKoA2J7jToW6z6WBmxR" > goodlink_exp &&
39 + echo QmcPNXE5zjkWkM24xQ7Bi3VAm8fRxiaNp88jFsij7kSQF1 > goodlink_exp &&
40 test_cmp goodlink_exp goodlink_out
41 '
42
43 test_expect_success "adding a broken symlink works" '
40 - ipfs add -q files/bad > badlink_out
44 + ipfs add -qr files/badin | head -1 > badlink_out
45 '
46
47 test_expect_success "output looks good" '
48 echo "QmWYN8SEXCgNT2PSjB6BnxAx6NJQtazWoBkTRH9GRfPFFQ" > badlink_exp &&
49 test_cmp badlink_exp badlink_out
50 '
51 +
52 + test_expect_success "adding with symlink in middle of path is same as\
53 +adding with no symlink" '
54 + ipfs add -rq files2/a/b/c > no_sym &&
55 + ipfs add -rq files2/a/d/c > sym &&
56 + test_cmp no_sym sym
57 + '
58 }
59
60 test_init_ipfs