Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
go-dms3
Commits
988b158d
Commit
988b158d
authored
9 years ago
by
Juan Batiz-Benet
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1276 from ipfs/debug/perm-fail
trying to debug permissions failure
parents
eff73ccc
cc905539
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
3 deletions
+26
-3
repo/fsrepo/lock/lock.go
repo/fsrepo/lock/lock.go
+25
-2
test/sharness/t0020-init.sh
test/sharness/t0020-init.sh
+1
-1
No files found.
repo/fsrepo/lock/lock.go
View file @
988b158d
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"
...
...
@@ -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
...
...
@@ -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
,
err
Perm
(
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"
)
}
This diff is collapsed.
Click to expand it.
test/sharness/t0020-init.sh
View file @
988b158d
...
...
@@ -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
'
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment