Skip to content

Commit 9ebc810

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* giteaofficial/main: Remove the Go version in UI, add a link on Gitea Version to show config details (Go/Git version) (go-gitea#19173) [skip ci] Updated translations via Crowdin Clean paths when looking in Storage (go-gitea#19124) Use the new/choose link for New Issue on project page (go-gitea#19172) Ensure that setting.LocalURL always has a trailing slash (go-gitea#19171) Use `ctx` instead of `db.DefaultContext` in some packages(routers/services/modules) (go-gitea#19163)
2 parents f9c05a9 + 395117d commit 9ebc810

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+188
-184
lines changed

cmd/admin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ func runChangePassword(c *cli.Context) error {
493493
return err
494494
}
495495

496-
if err = user_model.UpdateUserCols(db.DefaultContext, user, "passwd", "passwd_hash_algo", "salt"); err != nil {
496+
if err = user_model.UpdateUserCols(ctx, user, "passwd", "passwd_hash_algo", "salt"); err != nil {
497497
return err
498498
}
499499

modules/context/repo.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"strings"
1616

1717
"code.gitea.io/gitea/models"
18-
"code.gitea.io/gitea/models/db"
1918
repo_model "code.gitea.io/gitea/models/repo"
2019
unit_model "code.gitea.io/gitea/models/unit"
2120
user_model "code.gitea.io/gitea/models/user"
@@ -256,7 +255,7 @@ func RetrieveBaseRepo(ctx *Context, repo *repo_model.Repository) {
256255
}
257256
ctx.ServerError("GetBaseRepo", err)
258257
return
259-
} else if err = repo.BaseRepo.GetOwner(db.DefaultContext); err != nil {
258+
} else if err = repo.BaseRepo.GetOwner(ctx); err != nil {
260259
ctx.ServerError("BaseRepo.GetOwner", err)
261260
return
262261
}
@@ -273,7 +272,7 @@ func RetrieveTemplateRepo(ctx *Context, repo *repo_model.Repository) {
273272
}
274273
ctx.ServerError("GetTemplateRepo", err)
275274
return
276-
} else if err = templateRepo.GetOwner(db.DefaultContext); err != nil {
275+
} else if err = templateRepo.GetOwner(ctx); err != nil {
277276
ctx.ServerError("TemplateRepo.GetOwner", err)
278277
return
279278
}
@@ -341,7 +340,7 @@ func RedirectToRepo(ctx *Context, redirectRepoID int64) {
341340

342341
func repoAssignment(ctx *Context, repo *repo_model.Repository) {
343342
var err error
344-
if err = repo.GetOwner(db.DefaultContext); err != nil {
343+
if err = repo.GetOwner(ctx); err != nil {
345344
ctx.ServerError("GetOwner", err)
346345
return
347346
}

modules/doctor/checkOldArchives.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
func checkOldArchives(ctx context.Context, logger log.Logger, autofix bool) error {
1818
numRepos := 0
1919
numReposUpdated := 0
20-
err := iterateRepositories(func(repo *repo_model.Repository) error {
20+
err := iterateRepositories(ctx, func(repo *repo_model.Repository) error {
2121
if repo.IsEmpty {
2222
return nil
2323
}

modules/doctor/fix16961.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ func fixBrokenRepoUnits16961(ctx context.Context, logger log.Logger, autofix boo
268268
count := 0
269269

270270
err := db.Iterate(
271-
db.DefaultContext,
271+
ctx,
272272
new(RepoUnit),
273273
builder.Gt{
274274
"id": 0,

modules/doctor/mergebase.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ import (
1818
"xorm.io/builder"
1919
)
2020

21-
func iteratePRs(repo *repo_model.Repository, each func(*repo_model.Repository, *models.PullRequest) error) error {
21+
func iteratePRs(ctx context.Context, repo *repo_model.Repository, each func(*repo_model.Repository, *models.PullRequest) error) error {
2222
return db.Iterate(
23-
db.DefaultContext,
23+
ctx,
2424
new(models.PullRequest),
2525
builder.Eq{"base_repo_id": repo.ID},
2626
func(idx int, bean interface{}) error {
@@ -33,9 +33,9 @@ func checkPRMergeBase(ctx context.Context, logger log.Logger, autofix bool) erro
3333
numRepos := 0
3434
numPRs := 0
3535
numPRsUpdated := 0
36-
err := iterateRepositories(func(repo *repo_model.Repository) error {
36+
err := iterateRepositories(ctx, func(repo *repo_model.Repository) error {
3737
numRepos++
38-
return iteratePRs(repo, func(repo *repo_model.Repository, pr *models.PullRequest) error {
38+
return iteratePRs(ctx, repo, func(repo *repo_model.Repository, pr *models.PullRequest) error {
3939
numPRs++
4040
pr.BaseRepo = repo
4141
repoPath := repo.RepoPath()

modules/doctor/misc.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ import (
2727
"xorm.io/builder"
2828
)
2929

30-
func iterateRepositories(each func(*repo_model.Repository) error) error {
30+
func iterateRepositories(ctx context.Context, each func(*repo_model.Repository) error) error {
3131
err := db.Iterate(
32-
db.DefaultContext,
32+
ctx,
3333
new(repo_model.Repository),
3434
builder.Gt{"id": 0},
3535
func(idx int, bean interface{}) error {
@@ -50,7 +50,7 @@ func checkScriptType(ctx context.Context, logger log.Logger, autofix bool) error
5050
}
5151

5252
func checkHooks(ctx context.Context, logger log.Logger, autofix bool) error {
53-
if err := iterateRepositories(func(repo *repo_model.Repository) error {
53+
if err := iterateRepositories(ctx, func(repo *repo_model.Repository) error {
5454
results, err := repository.CheckDelegateHooks(repo.RepoPath())
5555
if err != nil {
5656
logger.Critical("Unable to check delegate hooks for repo %-v. ERROR: %v", repo, err)
@@ -86,7 +86,7 @@ func checkEnablePushOptions(ctx context.Context, logger log.Logger, autofix bool
8686
numRepos := 0
8787
numNeedUpdate := 0
8888

89-
if err := iterateRepositories(func(repo *repo_model.Repository) error {
89+
if err := iterateRepositories(ctx, func(repo *repo_model.Repository) error {
9090
numRepos++
9191
r, err := git.OpenRepositoryCtx(git.DefaultContext, repo.RepoPath())
9292
if err != nil {
@@ -132,13 +132,13 @@ func checkDaemonExport(ctx context.Context, logger log.Logger, autofix bool) err
132132
logger.Critical("Unable to create cache: %v", err)
133133
return err
134134
}
135-
if err := iterateRepositories(func(repo *repo_model.Repository) error {
135+
if err := iterateRepositories(ctx, func(repo *repo_model.Repository) error {
136136
numRepos++
137137

138138
if owner, has := cache.Get(repo.OwnerID); has {
139139
repo.Owner = owner.(*user_model.User)
140140
} else {
141-
if err := repo.GetOwner(db.DefaultContext); err != nil {
141+
if err := repo.GetOwner(ctx); err != nil {
142142
return err
143143
}
144144
cache.Add(repo.OwnerID, repo.Owner)

modules/repository/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ func MigrateRepositoryGitData(ctx context.Context, u *user_model.User,
156156
}
157157
}
158158

159-
if err = models.UpdateRepoSize(db.DefaultContext, repo); err != nil {
159+
if err = models.UpdateRepoSize(ctx, repo); err != nil {
160160
log.Error("Failed to update size for repository: %v", err)
161161
}
162162

modules/setting/setting.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,15 @@ var (
8989
// AppDataPath is the default path for storing data.
9090
// It maps to ini:"APP_DATA_PATH" and defaults to AppWorkPath + "/data"
9191
AppDataPath string
92+
// LocalURL is the url for locally running applications to contact Gitea. It always has a '/' suffix
93+
// It maps to ini:"LOCAL_ROOT_URL"
94+
LocalURL string
9295

9396
// Server settings
9497
Protocol Scheme
9598
Domain string
9699
HTTPAddr string
97100
HTTPPort string
98-
LocalURL string
99101
RedirectOtherPort bool
100102
PortToRedirect string
101103
OfflineMode bool
@@ -747,6 +749,7 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
747749
}
748750
}
749751
LocalURL = sec.Key("LOCAL_ROOT_URL").MustString(defaultLocalURL)
752+
LocalURL = strings.TrimRight(LocalURL, "/") + "/"
750753
RedirectOtherPort = sec.Key("REDIRECT_OTHER_PORT").MustBool(false)
751754
PortToRedirect = sec.Key("PORT_TO_REDIRECT").MustString("80")
752755
OfflineMode = sec.Key("OFFLINE_MODE").MustBool()

modules/storage/local.go

Lines changed: 8 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ package storage
66

77
import (
88
"context"
9-
"errors"
109
"io"
1110
"net/url"
1211
"os"
@@ -18,8 +17,6 @@ import (
1817
"code.gitea.io/gitea/modules/util"
1918
)
2019

21-
// ErrLocalPathNotSupported represents an error that path is not supported
22-
var ErrLocalPathNotSupported = errors.New("local path is not supported")
2320
var _ ObjectStorage = &LocalStorage{}
2421

2522
// LocalStorageType is the type descriptor for local storage
@@ -62,21 +59,18 @@ func NewLocalStorage(ctx context.Context, cfg interface{}) (ObjectStorage, error
6259
}, nil
6360
}
6461

62+
func (l *LocalStorage) buildLocalPath(p string) string {
63+
return filepath.Join(l.dir, path.Clean("/" + strings.ReplaceAll(p, "\\", "/"))[1:])
64+
}
65+
6566
// Open a file
6667
func (l *LocalStorage) Open(path string) (Object, error) {
67-
if !isLocalPathValid(path) {
68-
return nil, ErrLocalPathNotSupported
69-
}
70-
return os.Open(filepath.Join(l.dir, path))
68+
return os.Open(l.buildLocalPath(path))
7169
}
7270

7371
// Save a file
7472
func (l *LocalStorage) Save(path string, r io.Reader, size int64) (int64, error) {
75-
if !isLocalPathValid(path) {
76-
return 0, ErrLocalPathNotSupported
77-
}
78-
79-
p := filepath.Join(l.dir, path)
73+
p := l.buildLocalPath(path)
8074
if err := os.MkdirAll(filepath.Dir(p), os.ModePerm); err != nil {
8175
return 0, err
8276
}
@@ -116,24 +110,12 @@ func (l *LocalStorage) Save(path string, r io.Reader, size int64) (int64, error)
116110

117111
// Stat returns the info of the file
118112
func (l *LocalStorage) Stat(path string) (os.FileInfo, error) {
119-
return os.Stat(filepath.Join(l.dir, path))
120-
}
121-
122-
func isLocalPathValid(p string) bool {
123-
a := path.Clean(p)
124-
if strings.HasPrefix(a, "../") || strings.HasPrefix(a, "..\\") {
125-
return false
126-
}
127-
return a == p
113+
return os.Stat(l.buildLocalPath(path))
128114
}
129115

130116
// Delete delete a file
131117
func (l *LocalStorage) Delete(path string) error {
132-
if !isLocalPathValid(path) {
133-
return ErrLocalPathNotSupported
134-
}
135-
p := filepath.Join(l.dir, path)
136-
return util.Remove(p)
118+
return util.Remove(l.buildLocalPath(path))
137119
}
138120

139121
// URL gets the redirect URL to a file

modules/storage/local_test.go

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,36 +10,44 @@ import (
1010
"github.com/stretchr/testify/assert"
1111
)
1212

13-
func TestLocalPathIsValid(t *testing.T) {
13+
func TestBuildLocalPath(t *testing.T) {
1414
kases := []struct {
15-
path string
16-
valid bool
15+
localDir string
16+
path string
17+
expected string
1718
}{
1819
{
20+
"a",
21+
"0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
1922
"a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
20-
true,
2123
},
2224
{
23-
"../a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
24-
false,
25+
"a",
26+
"../0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
27+
"a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
2528
},
2629
{
27-
"a\\0\\a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
28-
true,
30+
"a",
31+
"0\\a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
32+
"a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
2933
},
3034
{
31-
"b/../a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
32-
false,
35+
"b",
36+
"a/../0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
37+
"b/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
3338
},
3439
{
35-
"..\\a/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
36-
false,
40+
"b",
41+
"a\\..\\0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
42+
"b/0/a0eebc99-9c0b-4ef8-bb6d-6bb9bd380a14",
3743
},
3844
}
3945

4046
for _, k := range kases {
4147
t.Run(k.path, func(t *testing.T) {
42-
assert.EqualValues(t, k.valid, isLocalPathValid(k.path))
48+
l := LocalStorage{dir: k.localDir}
49+
50+
assert.EqualValues(t, k.expected, l.buildLocalPath(k.path))
4351
})
4452
}
4553
}

modules/storage/minio.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ func NewMinioStorage(ctx context.Context, cfg interface{}) (ObjectStorage, error
117117
}
118118

119119
func (m *MinioStorage) buildMinioPath(p string) string {
120-
return strings.TrimPrefix(path.Join(m.basePath, p), "/")
120+
return strings.TrimPrefix(path.Join(m.basePath, path.Clean("/" + strings.ReplaceAll(p, "\\", "/"))[1:]), "/")
121121
}
122122

123123
// Open open a file

modules/test/context_tests.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import (
1414
"testing"
1515

1616
"code.gitea.io/gitea/models"
17-
"code.gitea.io/gitea/models/db"
1817
repo_model "code.gitea.io/gitea/models/repo"
1918
"code.gitea.io/gitea/models/unittest"
2019
user_model "code.gitea.io/gitea/models/user"
@@ -87,7 +86,7 @@ func LoadUser(t *testing.T, ctx *context.Context, userID int64) {
8786
// LoadGitRepo load a git repo into a test context. Requires that ctx.Repo has
8887
// already been populated.
8988
func LoadGitRepo(t *testing.T, ctx *context.Context) {
90-
assert.NoError(t, ctx.Repo.Repository.GetOwner(db.DefaultContext))
89+
assert.NoError(t, ctx.Repo.Repository.GetOwner(ctx))
9190
var err error
9291
ctx.Repo.GitRepo, err = git.OpenRepositoryCtx(ctx, ctx.Repo.Repository.RepoPath())
9392
assert.NoError(t, err)

options/locale/locale_pl-PL.ini

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ ssh_key_verify=Weryfikuj
625625
ssh_token_required=Musisz podać podpis poniższego tokenu
626626
ssh_token=Token
627627
ssh_token_help=Możesz wygenerować podpis używając:
628-
ssh_token_code=echo -n "%s" | ssh-keygen -Y znak -n gitea -f /ścieżka_do_twojego_klucza_publicznego
628+
ssh_token_code=echo -n "%s" | ssh-keygen -Y sign -n gitea -f /ścieżka_do_twojego_klucza_publicznego
629629
ssh_token_signature=Wzmocniony podpis SSH
630630
key_signature_ssh_placeholder=Zaczyna się od '-----BEGIN SSH SIGNATURE-----'
631631
verify_ssh_key_success=Klucz SSH '%s' został zweryfikowany.

routers/api/v1/org/org.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ func Edit(ctx *context.APIContext) {
346346
if form.RepoAdminChangeTeamAccess != nil {
347347
org.RepoAdminChangeTeamAccess = *form.RepoAdminChangeTeamAccess
348348
}
349-
if err := user_model.UpdateUserCols(db.DefaultContext, org.AsUser(),
349+
if err := user_model.UpdateUserCols(ctx, org.AsUser(),
350350
"full_name", "description", "website", "location",
351351
"visibility", "repo_admin_change_team_access",
352352
); err != nil {

routers/api/v1/repo/issue_stopwatch.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import (
99
"net/http"
1010

1111
"code.gitea.io/gitea/models"
12-
"code.gitea.io/gitea/models/db"
1312
"code.gitea.io/gitea/modules/context"
1413
"code.gitea.io/gitea/modules/convert"
1514
"code.gitea.io/gitea/routers/api/v1/utils"
@@ -56,7 +55,7 @@ func StartIssueStopwatch(ctx *context.APIContext) {
5655
return
5756
}
5857

59-
if err := models.CreateIssueStopwatch(db.DefaultContext, ctx.Doer, issue); err != nil {
58+
if err := models.CreateIssueStopwatch(ctx, ctx.Doer, issue); err != nil {
6059
ctx.Error(http.StatusInternalServerError, "CreateOrStopIssueStopwatch", err)
6160
return
6261
}
@@ -105,7 +104,7 @@ func StopIssueStopwatch(ctx *context.APIContext) {
105104
return
106105
}
107106

108-
if err := models.FinishIssueStopwatch(db.DefaultContext, ctx.Doer, issue); err != nil {
107+
if err := models.FinishIssueStopwatch(ctx, ctx.Doer, issue); err != nil {
109108
ctx.Error(http.StatusInternalServerError, "CreateOrStopIssueStopwatch", err)
110109
return
111110
}

routers/api/v1/repo/key.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func ListDeployKeys(ctx *context.APIContext) {
8787
Fingerprint: ctx.FormString("fingerprint"),
8888
}
8989

90-
keys, err := asymkey_model.ListDeployKeys(db.DefaultContext, opts)
90+
keys, err := asymkey_model.ListDeployKeys(ctx, opts)
9191
if err != nil {
9292
ctx.InternalServerError(err)
9393
return

routers/api/v1/repo/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ func Search(ctx *context.APIContext) {
217217

218218
results := make([]*api.Repository, len(repos))
219219
for i, repo := range repos {
220-
if err = repo.GetOwner(db.DefaultContext); err != nil {
220+
if err = repo.GetOwner(ctx); err != nil {
221221
ctx.JSON(http.StatusInternalServerError, api.SearchError{
222222
OK: false,
223223
Error: err.Error(),

routers/api/v1/user/gpg_key.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
)
1919

2020
func listGPGKeys(ctx *context.APIContext, uid int64, listOptions db.ListOptions) {
21-
keys, err := asymkey_model.ListGPGKeys(db.DefaultContext, uid, listOptions)
21+
keys, err := asymkey_model.ListGPGKeys(ctx, uid, listOptions)
2222
if err != nil {
2323
ctx.Error(http.StatusInternalServerError, "ListGPGKeys", err)
2424
return

0 commit comments

Comments
 (0)