@cryptotaxi247 / kubo / commits / e0bee137e

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.

Tommi Virtanen committed Mar 13, 2015 at 14:30 UTC e0bee137e9d6693e4d34a559bcb5946a7810e78d
2 files changed +2 -26
repo/fsrepo/fsrepo.go
+1 -14
@@ -38,8 +38,7 @@ var (
38 // lockfiles holds references to the Closers that ensure that repos are
39 // only accessed by one process at a time.
40 lockfiles map[string]io.Closer
41 - // openersCounter prevents the fsrepo from being removed while there exist open
42 - // FSRepo handles. It also ensures that the Init is atomic.
41 + // openersCounter ensures that the Init is atomic.
42 //
43 // packageLock also protects numOpenedRepos
44 //
@@ -165,15 +164,6 @@ func Init(repoPath string, conf *config.Config) error {
164 // Remove recursively removes the FSRepo at |path|.
165 func Remove(repoPath string) error {
166 repoPath = path.Clean(repoPath)
168 -
169 - // packageLock must be held to ensure that the repo is not removed while
170 - // being accessed by others.
171 - packageLock.Lock()
172 - defer packageLock.Unlock()
173 -
174 - if openersCounter.NumOpeners(repoPath) != 0 {
175 - return errors.New("repo in use")
176 - }
167 return os.RemoveAll(repoPath)
168 }
169
@@ -250,9 +240,6 @@ func configureEventLoggerAtRepoPath(c *config.Config, repoPath string) {
240 // Open returns an error if the repo is not initialized.
241 func (r *FSRepo) Open() error {
242
253 - // packageLock must be held to make sure that the repo is not destroyed by
254 - // another caller. It must not be released until initialization is complete
255 - // and the number of openers is incremeneted.
243 packageLock.Lock()
244 defer packageLock.Unlock()
245
repo/fsrepo/fsrepo_test.go
+1 -12
@@ -30,18 +30,7 @@ func TestInitIdempotence(t *testing.T) {
30 func TestRemove(t *testing.T) {
31 t.Parallel()
32 path := testRepoPath("foo", t)
33 - assert.Nil(Remove(path), t, "should be able to remove after closed")
34 -}
35 -
36 -func TestCannotRemoveIfOpen(t *testing.T) {
37 - t.Parallel()
38 - path := testRepoPath("TestCannotRemoveIfOpen", t)
39 - assert.Nil(Init(path, &config.Config{}), t, "should initialize successfully")
40 - r := At(path)
41 - assert.Nil(r.Open(), t)
42 - assert.Err(Remove(path), t, "should not be able to remove while open")
43 - assert.Nil(r.Close(), t)
44 - assert.Nil(Remove(path), t, "should be able to remove after closed")
33 + assert.Nil(Remove(path), t, "can remove a repository")
34 }
35
36 func TestCannotBeReopened(t *testing.T) {