mirror of https://github.com/harness/drone.git
fix: [CODE-3249]: Silent not found error on delete git repository (#3477)
parent
eef1c49da4
commit
2480779cdc
|
@ -23,6 +23,7 @@ import (
|
|||
"github.com/harness/gitness/app/auth"
|
||||
repoevents "github.com/harness/gitness/app/events/repo"
|
||||
"github.com/harness/gitness/app/githook"
|
||||
"github.com/harness/gitness/errors"
|
||||
"github.com/harness/gitness/git"
|
||||
"github.com/harness/gitness/types"
|
||||
"github.com/harness/gitness/types/enum"
|
||||
|
@ -123,7 +124,7 @@ func (c *Controller) DeleteGitRepository(
|
|||
err = c.git.DeleteRepository(ctx, &git.DeleteRepositoryParams{
|
||||
WriteParams: writeParams,
|
||||
})
|
||||
if err != nil {
|
||||
if err != nil && !errors.IsNotFound(err) {
|
||||
return fmt.Errorf("failed to remove git repository %s: %w", gitUID, err)
|
||||
}
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@ import (
|
|||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
|
@ -35,6 +34,7 @@ import (
|
|||
gitnessurl "github.com/harness/gitness/app/url"
|
||||
"github.com/harness/gitness/audit"
|
||||
"github.com/harness/gitness/encrypt"
|
||||
"github.com/harness/gitness/errors"
|
||||
"github.com/harness/gitness/git"
|
||||
"github.com/harness/gitness/job"
|
||||
gitness_store "github.com/harness/gitness/store"
|
||||
|
@ -493,7 +493,7 @@ func (r *Repository) deleteGitRepository(ctx context.Context,
|
|||
err = r.git.DeleteRepository(ctx, &git.DeleteRepositoryParams{
|
||||
WriteParams: writeParams,
|
||||
})
|
||||
if err != nil {
|
||||
if err != nil && !errors.IsNotFound(err) {
|
||||
return fmt.Errorf("failed to delete git repository: %w", err)
|
||||
}
|
||||
|
||||
|
|
11
git/repo.go
11
git/repo.go
|
@ -218,13 +218,6 @@ func (s *Service) DeleteRepository(ctx context.Context, params *DeleteRepository
|
|||
if err := params.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
repoPath := getFullPathForRepo(s.reposRoot, params.RepoUID)
|
||||
|
||||
if _, err := os.Stat(repoPath); err != nil && errors.Is(err, fs.ErrNotExist) {
|
||||
return errors.NotFound("repository path not found")
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("failed to check the status of the repository %v: %w", repoPath, err)
|
||||
}
|
||||
|
||||
return s.DeleteRepositoryBestEffort(ctx, params.RepoUID)
|
||||
}
|
||||
|
@ -243,7 +236,7 @@ func (s *Service) DeleteRepositoryBestEffort(ctx context.Context, repoUID string
|
|||
// move current dir to a temp dir (prevent partial deletion)
|
||||
err := os.Rename(repoPath, tempPath)
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
return nil // repository directory doesn't exist - nothing to do
|
||||
return errors.NotFound("repository path not found") // caller decides whether ignore this error
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("couldn't move dir %s to %s : %w", repoPath, tempPath, err)
|
||||
|
@ -424,7 +417,7 @@ func (s *Service) createRepositoryInternal(
|
|||
defer func() {
|
||||
if err != nil {
|
||||
cleanuperr := s.DeleteRepositoryBestEffort(ctx, base.RepoUID)
|
||||
if cleanuperr != nil {
|
||||
if cleanuperr != nil && !errors.IsNotFound(cleanuperr) {
|
||||
log.Warn().Err(cleanuperr).Msg("failed to cleanup repo dir")
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue