Commit e0bee137 authored by Tommi Virtanen's avatar Tommi Virtanen

fsrepo.Remove no longer checks for concurrently open instances

The only caller is `ipfs init`, which at that time does not hold a
repository open, and refuses to run on existing repos anyway.
parent bc55fb53
......@@ -38,8 +38,7 @@ var (
// lockfiles holds references to the Closers that ensure that repos are
// only accessed by one process at a time.
lockfiles map[string]io.Closer
// openersCounter prevents the fsrepo from being removed while there exist open
// FSRepo handles. It also ensures that the Init is atomic.
// openersCounter ensures that the Init is atomic.
//
// packageLock also protects numOpenedRepos
//
......@@ -165,15 +164,6 @@ func Init(repoPath string, conf *config.Config) error {
// Remove recursively removes the FSRepo at |path|.
func Remove(repoPath string) error {
repoPath = path.Clean(repoPath)
// packageLock must be held to ensure that the repo is not removed while
// being accessed by others.
packageLock.Lock()
defer packageLock.Unlock()
if openersCounter.NumOpeners(repoPath) != 0 {
return errors.New("repo in use")
}
return os.RemoveAll(repoPath)
}
......@@ -250,9 +240,6 @@ func configureEventLoggerAtRepoPath(c *config.Config, repoPath string) {
// Open returns an error if the repo is not initialized.
func (r *FSRepo) Open() error {
// packageLock must be held to make sure that the repo is not destroyed by
// another caller. It must not be released until initialization is complete
// and the number of openers is incremeneted.
packageLock.Lock()
defer packageLock.Unlock()
......
......@@ -30,18 +30,7 @@ func TestInitIdempotence(t *testing.T) {
func TestRemove(t *testing.T) {
t.Parallel()
path := testRepoPath("foo", t)
assert.Nil(Remove(path), t, "should be able to remove after closed")
}
func TestCannotRemoveIfOpen(t *testing.T) {
t.Parallel()
path := testRepoPath("TestCannotRemoveIfOpen", t)
assert.Nil(Init(path, &config.Config{}), t, "should initialize successfully")
r := At(path)
assert.Nil(r.Open(), t)
assert.Err(Remove(path), t, "should not be able to remove while open")
assert.Nil(r.Close(), t)
assert.Nil(Remove(path), t, "should be able to remove after closed")
assert.Nil(Remove(path), t, "can remove a repository")
}
func TestCannotBeReopened(t *testing.T) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment