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

Use path/filepath instead of path #8

Merged
merged 2 commits into from
Jul 10, 2019
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
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ go:
env:
global:
- GOTFLAGS="-race"
matrix:
- BUILD_DEPTYPE=gx
- BUILD_DEPTYPE=gomod


Expand Down
16 changes: 8 additions & 8 deletions fslock.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import (
"fmt"
"io"
"os"
"path"
"path/filepath"
"strings"
"syscall"

"github.com/ipfs/go-ipfs-util"
util "github.com/ipfs/go-ipfs-util"
logging "github.com/ipfs/go-log"
lock "go4.org/lock"
)
Expand All @@ -22,32 +22,32 @@ func errPerm(path string) error {

// Lock creates the lock.
func Lock(confdir, lockFile string) (io.Closer, error) {
return lock.Lock(path.Join(confdir, lockFile))
return lock.Lock(filepath.Join(confdir, lockFile))
}

// Locked checks if there is a lock already set.
func Locked(confdir, lockFile string) (bool, error) {
log.Debugf("Checking lock")
if !util.FileExists(path.Join(confdir, lockFile)) {
log.Debugf("File doesn't exist: %s", path.Join(confdir, lockFile))
if !util.FileExists(filepath.Join(confdir, lockFile)) {
log.Debugf("File doesn't exist: %s", filepath.Join(confdir, lockFile))
return false, nil
}

lk, err := Lock(confdir, lockFile)
if err != nil {
// EAGAIN == someone else has the lock
if err == syscall.EAGAIN {
log.Debugf("Someone else has the lock: %s", path.Join(confdir, lockFile))
log.Debugf("Someone else has the lock: %s", filepath.Join(confdir, lockFile))
return true, nil
}
if strings.Contains(err.Error(), "resource temporarily unavailable") {
log.Debugf("Can't lock file: %s.\n reason: %s", path.Join(confdir, lockFile), err.Error())
log.Debugf("Can't lock file: %s.\n reason: %s", filepath.Join(confdir, lockFile), err.Error())
return true, nil
}

// we hold the lock ourselves
if strings.Contains(err.Error(), "already locked") {
log.Debugf("Lock is already held by us: %s", path.Join(confdir, lockFile))
log.Debugf("Lock is already held by us: %s", filepath.Join(confdir, lockFile))
return true, nil
}

Expand Down