Skip to content

Commit 6ec07a6

Browse files
Phil Hopperappleboy
authored andcommitted
Make LocalCopyPath a setting instead of a hard-coded path (#1881)
1 parent cbdd5f7 commit 6ec07a6

File tree

4 files changed

+44
-1
lines changed

4 files changed

+44
-1
lines changed

conf/app.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,10 @@ LINE_WRAP_EXTENSIONS = .txt,.md,.markdown,.mdown,.mkd,
3232
; Separate values by commas. Preview tab in edit mode won't show if the file extension doesn't match
3333
PREVIEWABLE_FILE_MODES = markdown
3434

35+
[repository.local]
36+
; Path for uploads. Defaults to `tmp/local-repo`
37+
LOCAL_COPY_PATH = tmp/local-repo
38+
3539
[repository.upload]
3640
; Whether repository file uploads are enabled. Defaults to `true`
3741
ENABLED = true

models/repo.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,10 @@ func (repo *Repository) DescriptionHTML() template.HTML {
676676

677677
// LocalCopyPath returns the local repository copy path
678678
func (repo *Repository) LocalCopyPath() string {
679-
return path.Join(setting.AppDataPath, "tmp/local-repo", com.ToStr(repo.ID))
679+
if filepath.IsAbs(setting.Repository.Local.LocalCopyPath) {
680+
return path.Join(setting.Repository.Local.LocalCopyPath, com.ToStr(repo.ID))
681+
}
682+
return path.Join(setting.AppDataPath, setting.Repository.Local.LocalCopyPath, com.ToStr(repo.ID))
680683
}
681684

682685
// UpdateLocalCopyBranch pulls latest changes of given branch from repoPath to localPath.

models/repo_test.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,14 @@
55
package models
66

77
import (
8+
"path"
89
"testing"
910

1011
"code.gitea.io/gitea/modules/markdown"
12+
"code.gitea.io/gitea/modules/setting"
1113

1214
"github.com/stretchr/testify/assert"
15+
"github.com/Unknwon/com"
1316
)
1417

1518
func TestRepo(t *testing.T) {
@@ -132,3 +135,22 @@ func TestRepoAPIURL(t *testing.T) {
132135

133136
assert.Equal(t, "https://try.gitea.io/api/v1/repos/user12/repo10", repo.APIURL())
134137
}
138+
139+
func TestRepoLocalCopyPath(t *testing.T) {
140+
assert.NoError(t, PrepareTestDatabase())
141+
142+
repo, err := GetRepositoryByID(10)
143+
assert.NoError(t, err)
144+
assert.NotNil(t, repo)
145+
146+
// test default
147+
repoID := com.ToStr(repo.ID)
148+
expected := path.Join(setting.AppDataPath, setting.Repository.Local.LocalCopyPath, repoID)
149+
assert.Equal(t, expected, repo.LocalCopyPath())
150+
151+
// test absolute setting
152+
tempPath := "/tmp/gitea/local-copy-path"
153+
expected = path.Join(tempPath, repoID)
154+
setting.Repository.Local.LocalCopyPath = tempPath
155+
assert.Equal(t, expected, repo.LocalCopyPath())
156+
}

modules/setting/setting.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,11 @@ var (
174174
FileMaxSize int64
175175
MaxFiles int
176176
} `ini:"-"`
177+
178+
// Repository local settings
179+
Local struct {
180+
LocalCopyPath string
181+
} `ini:"-"`
177182
}{
178183
AnsiCharset: "",
179184
ForcePrivate: false,
@@ -206,6 +211,13 @@ var (
206211
FileMaxSize: 3,
207212
MaxFiles: 5,
208213
},
214+
215+
// Repository local settings
216+
Local: struct {
217+
LocalCopyPath string
218+
}{
219+
LocalCopyPath: "tmp/local-repo",
220+
},
209221
}
210222
RepoRootPath string
211223
ScriptType = "bash"
@@ -887,6 +899,8 @@ please consider changing to GITEA_CUSTOM`)
887899
log.Fatal(4, "Failed to map Repository.Editor settings: %v", err)
888900
} else if err = Cfg.Section("repository.upload").MapTo(&Repository.Upload); err != nil {
889901
log.Fatal(4, "Failed to map Repository.Upload settings: %v", err)
902+
} else if err = Cfg.Section("repository.local").MapTo(&Repository.Local); err != nil {
903+
log.Fatal(4, "Failed to map Repository.Local settings: %v", err)
890904
}
891905

892906
if !filepath.IsAbs(Repository.Upload.TempPath) {

0 commit comments

Comments
 (0)