From 07029ca32b1da05dc47d6cc54595b19a458e6292 Mon Sep 17 00:00:00 2001 From: John Reed Date: Sat, 14 Oct 2017 08:59:24 -0500 Subject: [PATCH 1/3] handle sym links in when calculating repo size repo/fsrepo: follow symbolic links when calculating RepoSize Now if the IPFS path is a symbolic it will be followed before calculating the repo size. License: MIT Signed-off-by: John Reed --- repo/fsrepo/fsrepo.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/repo/fsrepo/fsrepo.go b/repo/fsrepo/fsrepo.go index 0eaa8049ca6..0e65811886b 100644 --- a/repo/fsrepo/fsrepo.go +++ b/repo/fsrepo/fsrepo.go @@ -636,7 +636,13 @@ func (r *FSRepo) GetStorageUsage() (uint64, error) { if err != nil { return 0, err } - + + pth, err = filepath.EvalSymlinks(pth) + if err != nil { + log.Debugf("filepath.EvalSymlinks error: %s", err) + return 0, err + } + var du uint64 err = filepath.Walk(pth, func(p string, f os.FileInfo, err error) error { if err != nil { From 54d7e03303f70d88bfaa8a8aee636dd33b2dd491 Mon Sep 17 00:00:00 2001 From: Unknown Date: Sat, 21 Oct 2017 18:22:27 -0500 Subject: [PATCH 2/3] gofmt fix and sharness test gofmt fixes to fsrepo.go The sharness test checks that IPFS_PATHS that are symbolically linked to another directory are returning an appropriate size License: MIT Signed-off-by: John Reed --- repo/fsrepo/fsrepo.go | 4 ++-- test/sharness/t0088-repo-stat-symlink.sh | 27 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 test/sharness/t0088-repo-stat-symlink.sh diff --git a/repo/fsrepo/fsrepo.go b/repo/fsrepo/fsrepo.go index 0e65811886b..9d86c07e888 100644 --- a/repo/fsrepo/fsrepo.go +++ b/repo/fsrepo/fsrepo.go @@ -636,13 +636,13 @@ func (r *FSRepo) GetStorageUsage() (uint64, error) { if err != nil { return 0, err } - + pth, err = filepath.EvalSymlinks(pth) if err != nil { log.Debugf("filepath.EvalSymlinks error: %s", err) return 0, err } - + var du uint64 err = filepath.Walk(pth, func(p string, f os.FileInfo, err error) error { if err != nil { diff --git a/test/sharness/t0088-repo-stat-symlink.sh b/test/sharness/t0088-repo-stat-symlink.sh new file mode 100644 index 00000000000..a5ab95925cf --- /dev/null +++ b/test/sharness/t0088-repo-stat-symlink.sh @@ -0,0 +1,27 @@ +#!/bin/sh +# +# Copyright (c) 2017 John Reed +# MIT Licensed; see the LICENSE file in this repository. +# + +test_description="Test 'ipfs repo stat' where IPFS_PATH is a symbolic link" + +. lib/test-lib.sh + +test_expect_success "create symbolic link for IPFS_PATH" ' + mkdir sym_link_target && + ln -s sym_link_target .ipfs +' + +test_init_ipfs + +# compare RepoSize when getting it directly vs via symbolic link +test_expect_success "'ipfs repo stat' RepoSize is correct with sym link" ' + export IPFS_PATH="sym_link_target" && + reposize_direct=$(ipfs repo stat | grep RepoSize | awk '\''{ print $2 }'\'') && + export IPFS_PATH=".ipfs" && + reposize_symlink=$(ipfs repo stat | grep RepoSize | awk '\''{ print $2 }'\'') && + test $reposize_symlink -ge $reposize_direct +' + +test_done From 40a9036af8213a6f31cb39a446fa9e2762841c71 Mon Sep 17 00:00:00 2001 From: Unknown Date: Mon, 23 Oct 2017 07:50:47 -0500 Subject: [PATCH 3/3] set exec bit on sharness test setting the executable bit on sharness test License: MIT Signed-off-by: John Reed --- test/sharness/t0088-repo-stat-symlink.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 test/sharness/t0088-repo-stat-symlink.sh diff --git a/test/sharness/t0088-repo-stat-symlink.sh b/test/sharness/t0088-repo-stat-symlink.sh old mode 100644 new mode 100755