From 88e4b110badef2445f7336556a5cf6fe34f9a578 Mon Sep 17 00:00:00 2001 From: Kevin Atkinson Date: Sat, 27 Aug 2016 02:29:15 -0400 Subject: [PATCH 1/3] Revert "Resolve symlink if it is directly referenced in cli (#2897)" This reverts commit fe7b01f14e2b8db6e856b567dbd7db4d00f6e366. Conflicts: commands/cli/parse.go Revert "Merge pull request #3023 from ipfs/feature/eval-symlink-windows" This reverts commit 16c5a89dd44ea787f645e1fdfaf2e5b8ebb2945e, reversing changes made to 8c77ff81886da887bc33f1c775a4f8881d1281b5. Conflicts: commands/cli/parse.go License: MIT Signed-off-by: Kevin Atkinson --- commands/cli/parse.go | 8 +------- test/sharness/t0044-add-symlink.sh | 23 ++++++----------------- 2 files changed, 7 insertions(+), 24 deletions(-) diff --git a/commands/cli/parse.go b/commands/cli/parse.go index 672144a781f..25afa1f62b1 100644 --- a/commands/cli/parse.go +++ b/commands/cli/parse.go @@ -404,13 +404,7 @@ func appendFile(fpath string, argDef *cmds.Argument, recursive, hidden bool) (fi fpath = cwd } - fpath = filepath.Clean(fpath) - fpath, err := filepath.EvalSymlinks(fpath) - if err != nil { - return nil, err - } - // Repeat ToSlash after EvalSymlinks as it turns path to platform specific - fpath = filepath.ToSlash(fpath) + fpath = filepath.ToSlash(filepath.Clean(fpath)) stat, err := os.Lstat(fpath) if err != nil { diff --git a/test/sharness/t0044-add-symlink.sh b/test/sharness/t0044-add-symlink.sh index b7111bbfd39..13247b945f1 100755 --- a/test/sharness/t0044-add-symlink.sh +++ b/test/sharness/t0044-add-symlink.sh @@ -11,13 +11,9 @@ 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 ../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 + ln -s files/foo/baz files/bar/baz && + ln -s files/does/not/exist files/bad ' test_add_symlinks() { @@ -27,34 +23,27 @@ test_add_symlinks() { ' test_expect_success "output looks good" ' - echo QmQRgZT6xVFKJLVVpJDu3WcPkw2iqQ1jqK1F9jmdeq9zAv > filehash_exp && + echo QmWdiHKoeSW8G1u7ATCgpx4yMoUhYaJBQGkyPLkS9goYZ8 > filehash_exp && test_cmp filehash_exp filehash_out ' - test_expect_success "adding a symlink adds the file itself" ' + test_expect_success "adding a symlink adds the link itself" ' ipfs add -q files/bar/baz > goodlink_out ' test_expect_success "output looks good" ' - echo QmcPNXE5zjkWkM24xQ7Bi3VAm8fRxiaNp88jFsij7kSQF1 > goodlink_exp && + echo "QmdocmZeF7qwPT9Z8SiVhMSyKA2KKoA2J7jToW6z6WBmxR" > goodlink_exp && test_cmp goodlink_exp goodlink_out ' test_expect_success "adding a broken symlink works" ' - ipfs add -qr files/badin | head -1 > badlink_out + ipfs add -q files/bad > 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 From 10a692f9a294197fa97afdd5b538cf8116edcecd Mon Sep 17 00:00:00 2001 From: Kevin Atkinson Date: Sat, 27 Aug 2016 16:48:03 -0400 Subject: [PATCH 2/3] Fix "ipfs add -r ." to always add the contents of the current directory. License: MIT Signed-off-by: Kevin Atkinson --- commands/cli/parse.go | 4 ++++ test/sharness/t0040-add-and-cat.sh | 16 ++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/commands/cli/parse.go b/commands/cli/parse.go index 25afa1f62b1..3bb9f8c145e 100644 --- a/commands/cli/parse.go +++ b/commands/cli/parse.go @@ -401,6 +401,10 @@ func appendFile(fpath string, argDef *cmds.Argument, recursive, hidden bool) (fi if err != nil { return nil, err } + cwd, err = filepath.EvalSymlinks(cwd) + if err != nil { + return nil, err + } fpath = cwd } diff --git a/test/sharness/t0040-add-and-cat.sh b/test/sharness/t0040-add-and-cat.sh index 92f001762eb..fb6f6e7a0f4 100755 --- a/test/sharness/t0040-add-and-cat.sh +++ b/test/sharness/t0040-add-and-cat.sh @@ -189,6 +189,18 @@ test_add_named_pipe() { ' } +test_add_pwd_is_symlink() { + test_expect_success "ipfs add -r adds directory content when ./ is symlink" ' + mkdir hellodir && + echo "World" > hellodir/world && + ln -s hellodir hellolink && + ( cd hellolink && + ipfs add -r . > ../actual ) && + grep "added Qma9CyFdG5ffrZCcYSin2uAETygB25cswVwEYYzwfQuhTe" actual && + rm -r hellodir + ' +} + test_launch_ipfs_daemon_and_mount test_expect_success "'ipfs add --help' succeeds" ' @@ -354,6 +366,8 @@ test_add_cat_expensive test_add_named_pipe " Post http://$API_ADDR/api/v0/add?encoding=json&progress=true&r=true&stream-channels=true:" +test_add_pwd_is_symlink + test_kill_ipfs_daemon # should work offline @@ -371,6 +385,8 @@ test_expect_success "ipfs cat file fails" ' test_add_named_pipe "" +test_add_pwd_is_symlink + # Test daemon in offline mode test_launch_ipfs_daemon --offline From 802d3f9570401d5df420cb28fa973b57cef8a3e0 Mon Sep 17 00:00:00 2001 From: Kevin Atkinson Date: Mon, 29 Aug 2016 16:10:46 -0400 Subject: [PATCH 3/3] Add back still useful test from fe7b01f1 (Resolve symlink if ...) Add back still useful test from reverted commit: fe7b01f14e2b8db6e856b567dbd7db4d00f6e366 Resolve symlink if it is directly referenced in cli (#2897) License: MIT Signed-off-by: Kevin Atkinson --- test/sharness/t0044-add-symlink.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/sharness/t0044-add-symlink.sh b/test/sharness/t0044-add-symlink.sh index 13247b945f1..e2f5f416481 100755 --- a/test/sharness/t0044-add-symlink.sh +++ b/test/sharness/t0044-add-symlink.sh @@ -44,6 +44,16 @@ test_add_symlinks() { 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" ' + mkdir -p files2/a/b/c && + echo "some other text" > files2/a/b/c/foo && + ln -s b files2/a/d + 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