aboutsummaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorJakobDev <jakobdev@gmx.de>2023-09-15 08:13:19 +0200
committerGitHub <noreply@github.com>2023-09-15 06:13:19 +0000
commitc548dde205244a39a26ba98377c0f5cc11da7041 (patch)
treef9d9e1185609703e320ed07fd2ff3f95dbdcc230 /services
parentf8a109440655b77e8554e1744e31bf52a7c63df7 (diff)
downloadgitea-c548dde205244a39a26ba98377c0f5cc11da7041.tar.gz
gitea-c548dde205244a39a26ba98377c0f5cc11da7041.zip
More refactoring of `db.DefaultContext` (#27083)
Next step of #27065
Diffstat (limited to 'services')
-rw-r--r--services/asymkey/sign.go8
-rw-r--r--services/auth/basic.go6
-rw-r--r--services/auth/oauth2.go18
-rw-r--r--services/issue/content.go7
-rw-r--r--services/migrations/gitea_uploader_test.go2
-rw-r--r--services/org/repo.go6
-rw-r--r--services/org/repo_test.go5
-rw-r--r--services/packages/alpine/repository.go12
-rw-r--r--services/packages/debian/repository.go12
-rw-r--r--services/packages/rpm/repository.go15
-rw-r--r--services/pull/check.go2
-rw-r--r--services/repository/create_test.go2
-rw-r--r--services/repository/delete.go20
-rw-r--r--services/repository/delete_test.go2
-rw-r--r--services/repository/files/upload.go13
15 files changed, 66 insertions, 64 deletions
diff --git a/services/asymkey/sign.go b/services/asymkey/sign.go
index 252277e1bc..1598f32165 100644
--- a/services/asymkey/sign.go
+++ b/services/asymkey/sign.go
@@ -151,7 +151,7 @@ Loop:
return false, "", nil, &ErrWontSign{pubkey}
}
case twofa:
- twofaModel, err := auth.GetTwoFactorByUID(u.ID)
+ twofaModel, err := auth.GetTwoFactorByUID(ctx, u.ID)
if err != nil && !auth.IsErrTwoFactorNotEnrolled(err) {
return false, "", nil, err
}
@@ -187,7 +187,7 @@ Loop:
return false, "", nil, &ErrWontSign{pubkey}
}
case twofa:
- twofaModel, err := auth.GetTwoFactorByUID(u.ID)
+ twofaModel, err := auth.GetTwoFactorByUID(ctx, u.ID)
if err != nil && !auth.IsErrTwoFactorNotEnrolled(err) {
return false, "", nil, err
}
@@ -240,7 +240,7 @@ Loop:
return false, "", nil, &ErrWontSign{pubkey}
}
case twofa:
- twofaModel, err := auth.GetTwoFactorByUID(u.ID)
+ twofaModel, err := auth.GetTwoFactorByUID(ctx, u.ID)
if err != nil && !auth.IsErrTwoFactorNotEnrolled(err) {
return false, "", nil, err
}
@@ -302,7 +302,7 @@ Loop:
return false, "", nil, &ErrWontSign{pubkey}
}
case twofa:
- twofaModel, err := auth.GetTwoFactorByUID(u.ID)
+ twofaModel, err := auth.GetTwoFactorByUID(ctx, u.ID)
if err != nil && !auth.IsErrTwoFactorNotEnrolled(err) {
return false, "", nil, err
}
diff --git a/services/auth/basic.go b/services/auth/basic.go
index f3a9a8abce..bb9eb7a321 100644
--- a/services/auth/basic.go
+++ b/services/auth/basic.go
@@ -71,7 +71,7 @@ func (b *Basic) Verify(req *http.Request, w http.ResponseWriter, store DataStore
}
// check oauth2 token
- uid := CheckOAuthAccessToken(authToken)
+ uid := CheckOAuthAccessToken(req.Context(), authToken)
if uid != 0 {
log.Trace("Basic Authorization: Valid OAuthAccessToken for user[%d]", uid)
@@ -86,7 +86,7 @@ func (b *Basic) Verify(req *http.Request, w http.ResponseWriter, store DataStore
}
// check personal access token
- token, err := auth_model.GetAccessTokenBySHA(authToken)
+ token, err := auth_model.GetAccessTokenBySHA(req.Context(), authToken)
if err == nil {
log.Trace("Basic Authorization: Valid AccessToken for user[%d]", uid)
u, err := user_model.GetUserByID(req.Context(), token.UID)
@@ -96,7 +96,7 @@ func (b *Basic) Verify(req *http.Request, w http.ResponseWriter, store DataStore
}
token.UpdatedUnix = timeutil.TimeStampNow()
- if err = auth_model.UpdateAccessToken(token); err != nil {
+ if err = auth_model.UpdateAccessToken(req.Context(), token); err != nil {
log.Error("UpdateAccessToken: %v", err)
}
diff --git a/services/auth/oauth2.go b/services/auth/oauth2.go
index e621b5ffad..6572d661e8 100644
--- a/services/auth/oauth2.go
+++ b/services/auth/oauth2.go
@@ -5,13 +5,13 @@
package auth
import (
+ "context"
"net/http"
"strings"
"time"
actions_model "code.gitea.io/gitea/models/actions"
auth_model "code.gitea.io/gitea/models/auth"
- "code.gitea.io/gitea/models/db"
user_model "code.gitea.io/gitea/models/user"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/timeutil"
@@ -25,7 +25,7 @@ var (
)
// CheckOAuthAccessToken returns uid of user from oauth token
-func CheckOAuthAccessToken(accessToken string) int64 {
+func CheckOAuthAccessToken(ctx context.Context, accessToken string) int64 {
// JWT tokens require a "."
if !strings.Contains(accessToken, ".") {
return 0
@@ -36,7 +36,7 @@ func CheckOAuthAccessToken(accessToken string) int64 {
return 0
}
var grant *auth_model.OAuth2Grant
- if grant, err = auth_model.GetOAuth2GrantByID(db.DefaultContext, token.GrantID); err != nil || grant == nil {
+ if grant, err = auth_model.GetOAuth2GrantByID(ctx, token.GrantID); err != nil || grant == nil {
return 0
}
if token.Type != oauth2.TypeAccessToken {
@@ -83,21 +83,21 @@ func parseToken(req *http.Request) (string, bool) {
// userIDFromToken returns the user id corresponding to the OAuth token.
// It will set 'IsApiToken' to true if the token is an API token and
// set 'ApiTokenScope' to the scope of the access token
-func (o *OAuth2) userIDFromToken(tokenSHA string, store DataStore) int64 {
+func (o *OAuth2) userIDFromToken(ctx context.Context, tokenSHA string, store DataStore) int64 {
// Let's see if token is valid.
if strings.Contains(tokenSHA, ".") {
- uid := CheckOAuthAccessToken(tokenSHA)
+ uid := CheckOAuthAccessToken(ctx, tokenSHA)
if uid != 0 {
store.GetData()["IsApiToken"] = true
store.GetData()["ApiTokenScope"] = auth_model.AccessTokenScopeAll // fallback to all
}
return uid
}
- t, err := auth_model.GetAccessTokenBySHA(tokenSHA)
+ t, err := auth_model.GetAccessTokenBySHA(ctx, tokenSHA)
if err != nil {
if auth_model.IsErrAccessTokenNotExist(err) {
// check task token
- task, err := actions_model.GetRunningTaskByToken(db.DefaultContext, tokenSHA)
+ task, err := actions_model.GetRunningTaskByToken(ctx, tokenSHA)
if err == nil && task != nil {
log.Trace("Basic Authorization: Valid AccessToken for task[%d]", task.ID)
@@ -112,7 +112,7 @@ func (o *OAuth2) userIDFromToken(tokenSHA string, store DataStore) int64 {
return 0
}
t.UpdatedUnix = timeutil.TimeStampNow()
- if err = auth_model.UpdateAccessToken(t); err != nil {
+ if err = auth_model.UpdateAccessToken(ctx, t); err != nil {
log.Error("UpdateAccessToken: %v", err)
}
store.GetData()["IsApiToken"] = true
@@ -134,7 +134,7 @@ func (o *OAuth2) Verify(req *http.Request, w http.ResponseWriter, store DataStor
return nil, nil
}
- id := o.userIDFromToken(token, store)
+ id := o.userIDFromToken(req.Context(), token, store)
if id <= 0 && id != -2 { // -2 means actions, so we need to allow it.
return nil, user_model.ErrUserNotExist{}
diff --git a/services/issue/content.go b/services/issue/content.go
index cda11dbb18..41f1bfefe8 100644
--- a/services/issue/content.go
+++ b/services/issue/content.go
@@ -4,21 +4,22 @@
package issue
import (
- "code.gitea.io/gitea/models/db"
+ "context"
+
issues_model "code.gitea.io/gitea/models/issues"
user_model "code.gitea.io/gitea/models/user"
notify_service "code.gitea.io/gitea/services/notify"
)
// ChangeContent changes issue content, as the given user.
-func ChangeContent(issue *issues_model.Issue, doer *user_model.User, content string) (err error) {
+func ChangeContent(ctx context.Context, issue *issues_model.Issue, doer *user_model.User, content string) (err error) {
oldContent := issue.Content
if err := issues_model.ChangeIssueContent(issue, doer, content); err != nil {
return err
}
- notify_service.IssueChangeContent(db.DefaultContext, doer, issue, oldContent)
+ notify_service.IssueChangeContent(ctx, doer, issue, oldContent)
return nil
}
diff --git a/services/migrations/gitea_uploader_test.go b/services/migrations/gitea_uploader_test.go
index 878b6d6b84..e42d9e9286 100644
--- a/services/migrations/gitea_uploader_test.go
+++ b/services/migrations/gitea_uploader_test.go
@@ -113,7 +113,7 @@ func TestGiteaUploadRepo(t *testing.T) {
assert.NoError(t, issues[0].LoadDiscussComments(db.DefaultContext))
assert.Empty(t, issues[0].Comments)
- pulls, _, err := issues_model.PullRequests(repo.ID, &issues_model.PullRequestsOptions{
+ pulls, _, err := issues_model.PullRequests(db.DefaultContext, repo.ID, &issues_model.PullRequestsOptions{
SortType: "oldest",
})
assert.NoError(t, err)
diff --git a/services/org/repo.go b/services/org/repo.go
index 0edbf2d464..78a829ef25 100644
--- a/services/org/repo.go
+++ b/services/org/repo.go
@@ -14,14 +14,14 @@ import (
)
// TeamAddRepository adds new repository to team of organization.
-func TeamAddRepository(t *organization.Team, repo *repo_model.Repository) (err error) {
+func TeamAddRepository(ctx context.Context, t *organization.Team, repo *repo_model.Repository) (err error) {
if repo.OwnerID != t.OrgID {
return errors.New("repository does not belong to organization")
- } else if organization.HasTeamRepo(db.DefaultContext, t.OrgID, t.ID, repo.ID) {
+ } else if organization.HasTeamRepo(ctx, t.OrgID, t.ID, repo.ID) {
return nil
}
- return db.WithTx(db.DefaultContext, func(ctx context.Context) error {
+ return db.WithTx(ctx, func(ctx context.Context) error {
return models.AddRepository(ctx, t, repo)
})
}
diff --git a/services/org/repo_test.go b/services/org/repo_test.go
index 40b0d17077..68c64a01ab 100644
--- a/services/org/repo_test.go
+++ b/services/org/repo_test.go
@@ -6,6 +6,7 @@ package org
import (
"testing"
+ "code.gitea.io/gitea/models/db"
"code.gitea.io/gitea/models/organization"
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
@@ -19,7 +20,7 @@ func TestTeam_AddRepository(t *testing.T) {
testSuccess := func(teamID, repoID int64) {
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: teamID})
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: repoID})
- assert.NoError(t, TeamAddRepository(team, repo))
+ assert.NoError(t, TeamAddRepository(db.DefaultContext, team, repo))
unittest.AssertExistsAndLoadBean(t, &organization.TeamRepo{TeamID: teamID, RepoID: repoID})
unittest.CheckConsistencyFor(t, &organization.Team{ID: teamID}, &repo_model.Repository{ID: repoID})
}
@@ -28,6 +29,6 @@ func TestTeam_AddRepository(t *testing.T) {
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: 1})
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
- assert.Error(t, TeamAddRepository(team, repo))
+ assert.Error(t, TeamAddRepository(db.DefaultContext, team, repo))
unittest.CheckConsistencyFor(t, &organization.Team{ID: 1}, &repo_model.Repository{ID: 1})
}
diff --git a/services/packages/alpine/repository.go b/services/packages/alpine/repository.go
index 5264bd6c4a..24e673289a 100644
--- a/services/packages/alpine/repository.go
+++ b/services/packages/alpine/repository.go
@@ -39,13 +39,13 @@ func GetOrCreateRepositoryVersion(ownerID int64) (*packages_model.PackageVersion
}
// GetOrCreateKeyPair gets or creates the RSA keys used to sign repository files
-func GetOrCreateKeyPair(ownerID int64) (string, string, error) {
- priv, err := user_model.GetSetting(ownerID, alpine_module.SettingKeyPrivate)
+func GetOrCreateKeyPair(ctx context.Context, ownerID int64) (string, string, error) {
+ priv, err := user_model.GetSetting(ctx, ownerID, alpine_module.SettingKeyPrivate)
if err != nil && !errors.Is(err, util.ErrNotExist) {
return "", "", err
}
- pub, err := user_model.GetSetting(ownerID, alpine_module.SettingKeyPublic)
+ pub, err := user_model.GetSetting(ctx, ownerID, alpine_module.SettingKeyPublic)
if err != nil && !errors.Is(err, util.ErrNotExist) {
return "", "", err
}
@@ -56,11 +56,11 @@ func GetOrCreateKeyPair(ownerID int64) (string, string, error) {
return "", "", err
}
- if err := user_model.SetUserSetting(ownerID, alpine_module.SettingKeyPrivate, priv); err != nil {
+ if err := user_model.SetUserSetting(ctx, ownerID, alpine_module.SettingKeyPrivate, priv); err != nil {
return "", "", err
}
- if err := user_model.SetUserSetting(ownerID, alpine_module.SettingKeyPublic, pub); err != nil {
+ if err := user_model.SetUserSetting(ctx, ownerID, alpine_module.SettingKeyPublic, pub); err != nil {
return "", "", err
}
}
@@ -244,7 +244,7 @@ func buildPackagesIndex(ctx context.Context, ownerID int64, repoVersion *package
return err
}
- priv, _, err := GetOrCreateKeyPair(ownerID)
+ priv, _, err := GetOrCreateKeyPair(ctx, ownerID)
if err != nil {
return err
}
diff --git a/services/packages/debian/repository.go b/services/packages/debian/repository.go
index be82fbed6e..46b1a94b81 100644
--- a/services/packages/debian/repository.go
+++ b/services/packages/debian/repository.go
@@ -37,13 +37,13 @@ func GetOrCreateRepositoryVersion(ownerID int64) (*packages_model.PackageVersion
}
// GetOrCreateKeyPair gets or creates the PGP keys used to sign repository files
-func GetOrCreateKeyPair(ownerID int64) (string, string, error) {
- priv, err := user_model.GetSetting(ownerID, debian_module.SettingKeyPrivate)
+func GetOrCreateKeyPair(ctx context.Context, ownerID int64) (string, string, error) {
+ priv, err := user_model.GetSetting(ctx, ownerID, debian_module.SettingKeyPrivate)
if err != nil && !errors.Is(err, util.ErrNotExist) {
return "", "", err
}
- pub, err := user_model.GetSetting(ownerID, debian_module.SettingKeyPublic)
+ pub, err := user_model.GetSetting(ctx, ownerID, debian_module.SettingKeyPublic)
if err != nil && !errors.Is(err, util.ErrNotExist) {
return "", "", err
}
@@ -54,11 +54,11 @@ func GetOrCreateKeyPair(ownerID int64) (string, string, error) {
return "", "", err
}
- if err := user_model.SetUserSetting(ownerID, debian_module.SettingKeyPrivate, priv); err != nil {
+ if err := user_model.SetUserSetting(ctx, ownerID, debian_module.SettingKeyPrivate, priv); err != nil {
return "", "", err
}
- if err := user_model.SetUserSetting(ownerID, debian_module.SettingKeyPublic, pub); err != nil {
+ if err := user_model.SetUserSetting(ctx, ownerID, debian_module.SettingKeyPublic, pub); err != nil {
return "", "", err
}
}
@@ -306,7 +306,7 @@ func buildReleaseFiles(ctx context.Context, ownerID int64, repoVersion *packages
sort.Strings(architectures)
- priv, _, err := GetOrCreateKeyPair(ownerID)
+ priv, _, err := GetOrCreateKeyPair(ctx, ownerID)
if err != nil {
return err
}
diff --git a/services/packages/rpm/repository.go b/services/packages/rpm/repository.go
index cfd70ec23e..d115197197 100644
--- a/services/packages/rpm/repository.go
+++ b/services/packages/rpm/repository.go
@@ -38,13 +38,13 @@ func GetOrCreateRepositoryVersion(ownerID int64) (*packages_model.PackageVersion
}
// GetOrCreateKeyPair gets or creates the PGP keys used to sign repository metadata files
-func GetOrCreateKeyPair(ownerID int64) (string, string, error) {
- priv, err := user_model.GetSetting(ownerID, rpm_module.SettingKeyPrivate)
+func GetOrCreateKeyPair(ctx context.Context, ownerID int64) (string, string, error) {
+ priv, err := user_model.GetSetting(ctx, ownerID, rpm_module.SettingKeyPrivate)
if err != nil && !errors.Is(err, util.ErrNotExist) {
return "", "", err
}
- pub, err := user_model.GetSetting(ownerID, rpm_module.SettingKeyPublic)
+ pub, err := user_model.GetSetting(ctx, ownerID, rpm_module.SettingKeyPublic)
if err != nil && !errors.Is(err, util.ErrNotExist) {
return "", "", err
}
@@ -55,11 +55,11 @@ func GetOrCreateKeyPair(ownerID int64) (string, string, error) {
return "", "", err
}
- if err := user_model.SetUserSetting(ownerID, rpm_module.SettingKeyPrivate, priv); err != nil {
+ if err := user_model.SetUserSetting(ctx, ownerID, rpm_module.SettingKeyPrivate, priv); err != nil {
return "", "", err
}
- if err := user_model.SetUserSetting(ownerID, rpm_module.SettingKeyPublic, pub); err != nil {
+ if err := user_model.SetUserSetting(ctx, ownerID, rpm_module.SettingKeyPublic, pub); err != nil {
return "", "", err
}
}
@@ -212,6 +212,7 @@ func BuildRepositoryFiles(ctx context.Context, ownerID int64) error {
}
return buildRepomd(
+ ctx,
pv,
ownerID,
[]*repoData{
@@ -223,7 +224,7 @@ func BuildRepositoryFiles(ctx context.Context, ownerID int64) error {
}
// https://docs.pulpproject.org/en/2.19/plugins/pulp_rpm/tech-reference/rpm.html#repomd-xml
-func buildRepomd(pv *packages_model.PackageVersion, ownerID int64, data []*repoData) error {
+func buildRepomd(ctx context.Context, pv *packages_model.PackageVersion, ownerID int64, data []*repoData) error {
type Repomd struct {
XMLName xml.Name `xml:"repomd"`
Xmlns string `xml:"xmlns,attr"`
@@ -241,7 +242,7 @@ func buildRepomd(pv *packages_model.PackageVersion, ownerID int64, data []*repoD
return err
}
- priv, _, err := GetOrCreateKeyPair(ownerID)
+ priv, _, err := GetOrCreateKeyPair(ctx, ownerID)
if err != nil {
return err
}
diff --git a/services/pull/check.go b/services/pull/check.go
index dcb488c309..e4a0f6b27b 100644
--- a/services/pull/check.go
+++ b/services/pull/check.go
@@ -303,7 +303,7 @@ func manuallyMerged(ctx context.Context, pr *issues_model.PullRequest) bool {
// InitializePullRequests checks and tests untested patches of pull requests.
func InitializePullRequests(ctx context.Context) {
- prs, err := issues_model.GetPullRequestIDsByCheckStatus(issues_model.PullRequestStatusChecking)
+ prs, err := issues_model.GetPullRequestIDsByCheckStatus(ctx, issues_model.PullRequestStatusChecking)
if err != nil {
log.Error("Find Checking PRs: %v", err)
return
diff --git a/services/repository/create_test.go b/services/repository/create_test.go
index 7ffdcc38fb..36065cafff 100644
--- a/services/repository/create_test.go
+++ b/services/repository/create_test.go
@@ -28,7 +28,7 @@ func TestIncludesAllRepositoriesTeams(t *testing.T) {
assert.Len(t, team.Repos, len(repoIds), "%s: repo count", team.Name)
for i, rid := range repoIds {
if rid > 0 {
- assert.True(t, HasRepository(team, rid), "%s: HasRepository(%d) %d", rid, i)
+ assert.True(t, HasRepository(db.DefaultContext, team, rid), "%s: HasRepository(%d) %d", rid, i)
}
}
}
diff --git a/services/repository/delete.go b/services/repository/delete.go
index 8e28c9b255..f2b4781458 100644
--- a/services/repository/delete.go
+++ b/services/repository/delete.go
@@ -286,36 +286,36 @@ func DeleteRepositoryDirectly(ctx context.Context, doer *user_model.User, uid, r
// Remove repository files.
repoPath := repo.RepoPath()
- system_model.RemoveAllWithNotice(db.DefaultContext, "Delete repository files", repoPath)
+ system_model.RemoveAllWithNotice(ctx, "Delete repository files", repoPath)
// Remove wiki files
if repo.HasWiki() {
- system_model.RemoveAllWithNotice(db.DefaultContext, "Delete repository wiki", repo.WikiPath())
+ system_model.RemoveAllWithNotice(ctx, "Delete repository wiki", repo.WikiPath())
}
// Remove archives
for _, archive := range archivePaths {
- system_model.RemoveStorageWithNotice(db.DefaultContext, storage.RepoArchives, "Delete repo archive file", archive)
+ system_model.RemoveStorageWithNotice(ctx, storage.RepoArchives, "Delete repo archive file", archive)
}
// Remove lfs objects
for _, lfsObj := range lfsPaths {
- system_model.RemoveStorageWithNotice(db.DefaultContext, storage.LFS, "Delete orphaned LFS file", lfsObj)
+ system_model.RemoveStorageWithNotice(ctx, storage.LFS, "Delete orphaned LFS file", lfsObj)
}
// Remove issue attachment files.
for _, attachment := range attachmentPaths {
- system_model.RemoveStorageWithNotice(db.DefaultContext, storage.Attachments, "Delete issue attachment", attachment)
+ system_model.RemoveStorageWithNotice(ctx, storage.Attachments, "Delete issue attachment", attachment)
}
// Remove release attachment files.
for _, releaseAttachment := range releaseAttachments {
- system_model.RemoveStorageWithNotice(db.DefaultContext, storage.Attachments, "Delete release attachment", releaseAttachment)
+ system_model.RemoveStorageWithNotice(ctx, storage.Attachments, "Delete release attachment", releaseAttachment)
}
// Remove attachment with no issue_id and release_id.
for _, newAttachment := range newAttachmentPaths {
- system_model.RemoveStorageWithNotice(db.DefaultContext, storage.Attachments, "Delete issue attachment", newAttachment)
+ system_model.RemoveStorageWithNotice(ctx, storage.Attachments, "Delete issue attachment", newAttachment)
}
if len(repo.Avatar) > 0 {
@@ -390,14 +390,14 @@ func removeRepositoryFromTeam(ctx context.Context, t *organization.Team, repo *r
}
// HasRepository returns true if given repository belong to team.
-func HasRepository(t *organization.Team, repoID int64) bool {
- return organization.HasTeamRepo(db.DefaultContext, t.OrgID, t.ID, repoID)
+func HasRepository(ctx context.Context, t *organization.Team, repoID int64) bool {
+ return organization.HasTeamRepo(ctx, t.OrgID, t.ID, repoID)
}
// RemoveRepositoryFromTeam removes repository from team of organization.
// If the team shall include all repositories the request is ignored.
func RemoveRepositoryFromTeam(ctx context.Context, t *organization.Team, repoID int64) error {
- if !HasRepository(t, repoID) {
+ if !HasRepository(ctx, t, repoID) {
return nil
}
diff --git a/services/repository/delete_test.go b/services/repository/delete_test.go
index 2905c01868..ae5fd53962 100644
--- a/services/repository/delete_test.go
+++ b/services/repository/delete_test.go
@@ -19,7 +19,7 @@ func TestTeam_HasRepository(t *testing.T) {
test := func(teamID, repoID int64, expected bool) {
team := unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: teamID})
- assert.Equal(t, expected, HasRepository(team, repoID))
+ assert.Equal(t, expected, HasRepository(db.DefaultContext, team, repoID))
}
test(1, 1, false)
test(1, 3, true)
diff --git a/services/repository/files/upload.go b/services/repository/files/upload.go
index 338811f0f1..f4e1da7bb1 100644
--- a/services/repository/files/upload.go
+++ b/services/repository/files/upload.go
@@ -10,7 +10,6 @@ import (
"path"
"strings"
- "code.gitea.io/gitea/models/db"
git_model "code.gitea.io/gitea/models/git"
repo_model "code.gitea.io/gitea/models/repo"
user_model "code.gitea.io/gitea/models/user"
@@ -35,13 +34,13 @@ type uploadInfo struct {
lfsMetaObject *git_model.LFSMetaObject
}
-func cleanUpAfterFailure(infos *[]uploadInfo, t *TemporaryUploadRepository, original error) error {
+func cleanUpAfterFailure(ctx context.Context, infos *[]uploadInfo, t *TemporaryUploadRepository, original error) error {
for _, info := range *infos {
if info.lfsMetaObject == nil {
continue
}
if !info.lfsMetaObject.Existing {
- if _, err := git_model.RemoveLFSMetaObjectByOid(db.DefaultContext, t.repo.ID, info.lfsMetaObject.Oid); err != nil {
+ if _, err := git_model.RemoveLFSMetaObjectByOid(ctx, t.repo.ID, info.lfsMetaObject.Oid); err != nil {
original = fmt.Errorf("%w, %v", original, err) // We wrap the original error - as this is the underlying error that required the fallback
}
}
@@ -55,7 +54,7 @@ func UploadRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *use
return nil
}
- uploads, err := repo_model.GetUploadsByUUIDs(opts.Files)
+ uploads, err := repo_model.GetUploadsByUUIDs(ctx, opts.Files)
if err != nil {
return fmt.Errorf("GetUploadsByUUIDs [uuids: %v]: %w", opts.Files, err)
}
@@ -147,7 +146,7 @@ func UploadRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *use
infos[i].lfsMetaObject, err = git_model.NewLFSMetaObject(ctx, infos[i].lfsMetaObject)
if err != nil {
// OK Now we need to cleanup
- return cleanUpAfterFailure(&infos, t, err)
+ return cleanUpAfterFailure(ctx, &infos, t, err)
}
// Don't move the files yet - we need to ensure that
// everything can be inserted first
@@ -158,7 +157,7 @@ func UploadRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *use
contentStore := lfs.NewContentStore()
for _, info := range infos {
if err := uploadToLFSContentStore(info, contentStore); err != nil {
- return cleanUpAfterFailure(&infos, t, err)
+ return cleanUpAfterFailure(ctx, &infos, t, err)
}
}
@@ -167,7 +166,7 @@ func UploadRepoFiles(ctx context.Context, repo *repo_model.Repository, doer *use
return err
}
- return repo_model.DeleteUploads(uploads...)
+ return repo_model.DeleteUploads(ctx, uploads...)
}
func copyUploadedLFSFileIntoRepository(info *uploadInfo, filename2attribute2info map[string]map[string]string, t *TemporaryUploadRepository, treePath string) error {