Skip to content

Commit

Permalink
refactor: extract fs lock into go-fs-lock
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: dignifiedquire <dignifiedquire@gmail.com>
  • Loading branch information
dignifiedquire committed Feb 16, 2018
1 parent 53af453 commit 5243400
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 76 deletions.
3 changes: 1 addition & 2 deletions core/commands/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
corerepo "github.com/ipfs/go-ipfs/core/corerepo"
config "github.com/ipfs/go-ipfs/repo/config"
fsrepo "github.com/ipfs/go-ipfs/repo/fsrepo"
lockfile "github.com/ipfs/go-ipfs/repo/fsrepo/lock"

bstore "gx/ipfs/QmTVDM4LCSUMFNQzbDLL9zQwp8usE6QHymFdh3h8vL9v6b/go-ipfs-blockstore"
cmds "gx/ipfs/QmZ9hww8R3FKrDRCYPxhN13m6XgjPDpaSvdUfisPvERzXz/go-ipfs-cmds"
Expand Down Expand Up @@ -233,7 +232,7 @@ daemons are running.
}

dsLockFile := filepath.Join(dsPath, "LOCK") // TODO: get this lockfile programmatically
repoLockFile := filepath.Join(configRoot, lockfile.LockFile)
repoLockFile := filepath.Join(configRoot, fsrepo.LockFile)
apiFile := filepath.Join(configRoot, "api") // TODO: get this programmatically

log.Infof("Removing repo lockfile: %s", repoLockFile)
Expand Down
7 changes: 6 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,12 @@
"hash": "QmdbxjQWogRCHRaxhhGnYdT1oQJzL9GdqSKzCdqWr85AP2",
"name": "pubsub",
"version": "1.0.0"
},
{
"author": "dignifiedquire",
"hash": "QmTAQSKWDGV7MpNGZrcj9gzbBLk3vG77EcBkCQtPphCknP",
"name": "go-fs-lock",
"version": "0.1.0"
}
],
"gxVersion": "0.10.0",
Expand All @@ -583,4 +589,3 @@
"name": "go-ipfs",
"version": "0.4.14-dev"
}

10 changes: 7 additions & 3 deletions repo/fsrepo/fsrepo.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import (
repo "github.com/ipfs/go-ipfs/repo"
"github.com/ipfs/go-ipfs/repo/common"
config "github.com/ipfs/go-ipfs/repo/config"
lockfile "github.com/ipfs/go-ipfs/repo/fsrepo/lock"
mfsr "github.com/ipfs/go-ipfs/repo/fsrepo/migrations"
serialize "github.com/ipfs/go-ipfs/repo/fsrepo/serialize"
dir "github.com/ipfs/go-ipfs/thirdparty/dir"
lockfile "gx/ipfs/QmTAQSKWDGV7MpNGZrcj9gzbBLk3vG77EcBkCQtPphCknP/go-fs-lock"

"github.com/ipfs/go-ipfs/Godeps/_workspace/src/github.com/mitchellh/go-homedir"

Expand All @@ -29,6 +29,10 @@ import (
ma "gx/ipfs/QmWWQ2Txc2c6tqjsBpzg5Ar652cHPGNsQQp2SejkNmkUMb/go-multiaddr"
)

// LockFile is the filename of the repo lock, relative to config dir
// TODO rename repo lock and hide name
const LockFile = "repo.lock"

var log = logging.Logger("fsrepo")

// version number that we are currently expecting to see
Expand Down Expand Up @@ -126,7 +130,7 @@ func open(repoPath string) (repo.Repo, error) {
return nil, err
}

r.lockfile, err = lockfile.Lock(r.path)
r.lockfile, err = lockfile.Lock(r.path, LockFile)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -297,7 +301,7 @@ func Init(repoPath string, conf *config.Config) error {
// process. If true, then the repo cannot be opened by this process.
func LockedByOtherProcess(repoPath string) (bool, error) {
repoPath = filepath.Clean(repoPath)
locked, err := lockfile.Locked(repoPath)
locked, err := lockfile.Locked(repoPath, LockFile)
if locked {
log.Debugf("(%t)<->Lock is held at %s", locked, repoPath)
}
Expand Down
70 changes: 0 additions & 70 deletions repo/fsrepo/lock/lock.go

This file was deleted.

0 comments on commit 5243400

Please sign in to comment.