Skip to content

Commit

Permalink
fix: remove repo when stat mismatch
Browse files Browse the repository at this point in the history
Remove repo files when the repo doesn't exist in the database but exists
in the filesystem
  • Loading branch information
aymanbagabas committed Aug 4, 2023
1 parent babc52f commit da5bf4e
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions server/backend/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,17 @@ func (d *Backend) DeleteRepository(ctx context.Context, name string) error {
// Delete repo from cache
defer d.cache.Delete(name)

repom, err := d.store.GetRepoByName(ctx, tx, name)
if err != nil {
return db.WrapError(err)
repom, dberr := d.store.GetRepoByName(ctx, tx, name)
_, ferr := os.Stat(rp)
if dberr != nil && ferr != nil {
return proto.ErrRepoNotFound
}

// If the repo is not in the database but the directory exists, remove it
if dberr != nil && ferr == nil {
return os.RemoveAll(rp)
} else if dberr != nil {
return db.WrapError(dberr)
}

repoID := strconv.FormatInt(repom.ID, 10)
Expand Down

0 comments on commit da5bf4e

Please sign in to comment.