Skip to content

Commit

Permalink
Merge pull request #1276 from ipfs/debug/perm-fail
Browse files Browse the repository at this point in the history
trying to debug permissions failure
  • Loading branch information
jbenet committed May 22, 2015
2 parents eff73cc + cc90553 commit 988b158
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
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)
}

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

0 comments on commit 988b158

Please sign in to comment.