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

trying to debug permissions failure #1276

Merged
merged 1 commit into from
May 22, 2015
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
27 changes: 25 additions & 2 deletions repo/fsrepo/lock/lock.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package lock

import (
"fmt"
"io"
"os"
"path"
"strings"
"syscall"

lock "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/camlistore/lock"
"github.com/ipfs/go-ipfs/util"
Expand All @@ -13,6 +16,10 @@ import (
// TODO rename repo lock and hide name
const LockFile = "repo.lock"

func errPerm(path string) error {
return fmt.Errorf("failed to take lock at %s: permission denied", path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe:

"locking %s: permission denied"

so that the error prints as:

Error: locking <path>: permission denied.

(but maybe this is fine)

}

func Lock(confdir string) (io.Closer, error) {
c, err := lock.Lock(path.Join(confdir, LockFile))
return c, err
Expand All @@ -23,12 +30,28 @@ func Locked(confdir string) (bool, error) {
return false, nil
}
if lk, err := Lock(confdir); err != nil {
// EAGAIN == someone else has the lock
if err == syscall.EAGAIN {
return true, nil
}

// lock fails on permissions error
if os.IsPermission(err) {
return false, err
return false, errPerm(confdir)
}
return true, nil
if isLockCreatePermFail(err) {
return false, errPerm(confdir)
}

// otherwise, we cant guarantee anything, error out
return false, err
} else {
lk.Close()
return false, nil
}
}

func isLockCreatePermFail(err error) bool {
s := err.Error()
return strings.Contains(s, "Lock Create of") && strings.Contains(s, "permission denied")
}
2 changes: 1 addition & 1 deletion test/sharness/t0020-init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test_expect_success "ipfs init fails" '
'

test_expect_success "ipfs init output looks good" '
echo "Error: open $IPFS_PATH/repo.lock: permission denied" > init_fail_exp &&
echo "Error: failed to take lock at $IPFS_PATH: permission denied" > init_fail_exp &&
test_cmp init_fail_out init_fail_exp
'

Expand Down