@cryptotaxi247 / kubo / commits / cc905539a

trying to debug permissions failure

Jeromy committed May 21, 2015 at 15:24 UTC cc905539ae91d2403ce8893d08747d384c717c41
2 files changed +26 -3
repo/fsrepo/lock/lock.go
+25 -2
@@ -1,9 +1,12 @@
1 package lock
2
3 import (
4 + "fmt"
5 "io"
6 "os"
7 "path"
8 + "strings"
9 + "syscall"
10
11 lock "github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/camlistore/lock"
12 "github.com/ipfs/go-ipfs/util"
@@ -13,6 +16,10 @@ import (
16 // TODO rename repo lock and hide name
17 const LockFile = "repo.lock"
18
19 +func errPerm(path string) error {
20 + return fmt.Errorf("failed to take lock at %s: permission denied", path)
21 +}
22 +
23 func Lock(confdir string) (io.Closer, error) {
24 c, err := lock.Lock(path.Join(confdir, LockFile))
25 return c, err
@@ -23,12 +30,28 @@ func Locked(confdir string) (bool, error) {
30 return false, nil
31 }
32 if lk, err := Lock(confdir); err != nil {
33 + // EAGAIN == someone else has the lock
34 + if err == syscall.EAGAIN {
35 + return true, nil
36 + }
37 +
38 + // lock fails on permissions error
39 if os.IsPermission(err) {
27 - return false, err
40 + return false, errPerm(confdir)
41 }
29 - return true, nil
42 + if isLockCreatePermFail(err) {
43 + return false, errPerm(confdir)
44 + }
45 +
46 + // otherwise, we cant guarantee anything, error out
47 + return false, err
48 } else {
49 lk.Close()
50 return false, nil
51 }
52 }
53 +
54 +func isLockCreatePermFail(err error) bool {
55 + s := err.Error()
56 + return strings.Contains(s, "Lock Create of") && strings.Contains(s, "permission denied")
57 +}
test/sharness/t0020-init.sh
+1 -1
@@ -20,7 +20,7 @@ test_expect_success "ipfs init fails" '
20 '
21
22 test_expect_success "ipfs init output looks good" '
23 - echo "Error: open $IPFS_PATH/repo.lock: permission denied" > init_fail_exp &&
23 + echo "Error: failed to take lock at $IPFS_PATH: permission denied" > init_fail_exp &&
24 test_cmp init_fail_out init_fail_exp
25 '
26