Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle sym links in when calculating repo size #4305

Merged
merged 3 commits into from
Oct 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions repo/fsrepo/fsrepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,12 @@ func (r *FSRepo) GetStorageUsage() (uint64, error) {
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 {
Expand Down
27 changes: 27 additions & 0 deletions test/sharness/t0088-repo-stat-symlink.sh
Original file line number Diff line number Diff line change
@@ -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