1
0
mirror of https://github.com/ipfs/kubo.git synced 2025-09-10 14:34:24 +08:00

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.
This commit is contained in:
Tommi Virtanen
2015-03-13 14:30:05 -07:00
parent bc55fb539f
commit e0bee137e9
2 changed files with 2 additions and 26 deletions

View File

@ -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()

View File

@ -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) {