Skip to content

Commit 988b158

Browse files
committedMay 22, 2015
Merge pull request #1276 from ipfs/debug/perm-fail
trying to debug permissions failure
2 parents eff73cc + cc90553 commit 988b158

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed
 

‎repo/fsrepo/lock/lock.go

+25-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
package lock
22

33
import (
4+
"fmt"
45
"io"
56
"os"
67
"path"
8+
"strings"
9+
"syscall"
710

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

19+
func errPerm(path string) error {
20+
return fmt.Errorf("failed to take lock at %s: permission denied", path)
21+
}
22+
1623
func Lock(confdir string) (io.Closer, error) {
1724
c, err := lock.Lock(path.Join(confdir, LockFile))
1825
return c, err
@@ -23,12 +30,28 @@ func Locked(confdir string) (bool, error) {
2330
return false, nil
2431
}
2532
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
2639
if os.IsPermission(err) {
27-
return false, err
40+
return false, errPerm(confdir)
2841
}
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
3048
} else {
3149
lk.Close()
3250
return false, nil
3351
}
3452
}
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
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ test_expect_success "ipfs init fails" '
2020
'
2121

2222
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 &&
2424
test_cmp init_fail_out init_fail_exp
2525
'
2626

0 commit comments

Comments
 (0)