Skip to content

Commit 7949fce

Browse files
authored
Merge branch 'master' into reviewed
2 parents 3874ded + acd5e5a commit 7949fce

File tree

10 files changed

+147
-22
lines changed

10 files changed

+147
-22
lines changed

models/repo.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ func loadRepoConfig() {
7979
log.Fatal("Failed to get custom %s files: %v", t, err)
8080
}
8181
if isDir {
82-
customFiles, err := com.StatDir(customPath)
82+
customFiles, err := util.StatDir(customPath)
8383
if err != nil {
8484
log.Fatal("Failed to get custom %s files: %v", t, err)
8585
}

modules/options/dynamic.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import (
1414
"code.gitea.io/gitea/modules/log"
1515
"code.gitea.io/gitea/modules/setting"
1616
"code.gitea.io/gitea/modules/util"
17-
18-
"github.com/unknwon/com"
1917
)
2018

2119
var (
@@ -39,7 +37,7 @@ func Dir(name string) ([]string, error) {
3937
return []string{}, fmt.Errorf("Unabe to check if custom directory %s is a directory. %v", customDir, err)
4038
}
4139
if isDir {
42-
files, err := com.StatDir(customDir, true)
40+
files, err := util.StatDir(customDir, true)
4341

4442
if err != nil {
4543
return []string{}, fmt.Errorf("Failed to read custom directory. %v", err)
@@ -55,7 +53,7 @@ func Dir(name string) ([]string, error) {
5553
return []string{}, fmt.Errorf("Unabe to check if static directory %s is a directory. %v", staticDir, err)
5654
}
5755
if isDir {
58-
files, err := com.StatDir(staticDir, true)
56+
files, err := util.StatDir(staticDir, true)
5957

6058
if err != nil {
6159
return []string{}, fmt.Errorf("Failed to read static directory. %v", err)

modules/options/static.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import (
1414
"code.gitea.io/gitea/modules/log"
1515
"code.gitea.io/gitea/modules/setting"
1616
"code.gitea.io/gitea/modules/util"
17-
18-
"github.com/unknwon/com"
1917
)
2018

2119
var (
@@ -38,7 +36,7 @@ func Dir(name string) ([]string, error) {
3836
return []string{}, fmt.Errorf("Failed to check if custom directory %s is a directory. %v", err)
3937
}
4038
if isDir {
41-
files, err := com.StatDir(customDir, true)
39+
files, err := util.StatDir(customDir, true)
4240

4341
if err != nil {
4442
return []string{}, fmt.Errorf("Failed to read custom directory. %v", err)

modules/setting/storage.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,20 +43,36 @@ func getStorage(name, typ string, targetSec *ini.Section) Storage {
4343
sec.Key("MINIO_LOCATION").MustString("us-east-1")
4444
sec.Key("MINIO_USE_SSL").MustBool(false)
4545

46-
nameSec := Cfg.Section(sectionName + "." + name)
47-
typeSec := Cfg.Section(sectionName + "." + typ)
48-
for _, override := range []*ini.Section{nameSec, typeSec, sec} {
46+
var storage Storage
47+
storage.Section = targetSec
48+
storage.Type = typ
49+
50+
overrides := make([]*ini.Section, 0, 3)
51+
nameSec, err := Cfg.GetSection(sectionName + "." + name)
52+
if err == nil {
53+
overrides = append(overrides, nameSec)
54+
}
55+
56+
typeSec, err := Cfg.GetSection(sectionName + "." + typ)
57+
if err == nil {
58+
overrides = append(overrides, typeSec)
59+
nextType := typeSec.Key("STORAGE_TYPE").String()
60+
if len(nextType) > 0 {
61+
storage.Type = nextType // Support custom STORAGE_TYPE
62+
}
63+
}
64+
overrides = append(overrides, sec)
65+
66+
for _, override := range overrides {
4967
for _, key := range override.Keys() {
5068
if !targetSec.HasKey(key.Name()) {
5169
_, _ = targetSec.NewKey(key.Name(), key.Value())
5270
}
5371
}
72+
if len(storage.Type) == 0 {
73+
storage.Type = override.Key("STORAGE_TYPE").String()
74+
}
5475
}
55-
56-
var storage Storage
57-
storage.Section = targetSec
58-
59-
storage.Type = typeSec.Key("STORAGE_TYPE").MustString(typ)
6076
storage.ServeDirect = storage.Section.Key("SERVE_DIRECT").MustBool(false)
6177

6278
// Specific defaults

modules/setting/storage_test.go

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,22 @@ MINIO_BUCKET = gitea
7777
func Test_getStorageSpecificOverridesStorage(t *testing.T) {
7878
iniStr := `
7979
[attachment]
80+
STORAGE_TYPE = minio
8081
MINIO_BUCKET = gitea-attachment
8182
8283
[storage.attachments]
8384
MINIO_BUCKET = gitea
85+
86+
[storage]
87+
STORAGE_TYPE = local
8488
`
8589
Cfg, _ = ini.Load([]byte(iniStr))
8690

8791
sec := Cfg.Section("attachment")
8892
storageType := sec.Key("STORAGE_TYPE").MustString("")
8993
storage := getStorage("attachments", storageType, sec)
9094

95+
assert.EqualValues(t, "minio", storage.Type)
9196
assert.EqualValues(t, "gitea-attachment", storage.Section.Key("MINIO_BUCKET").String())
9297
}
9398

@@ -162,3 +167,31 @@ MINIO_BUCKET = gitea-storage
162167
assert.EqualValues(t, "gitea-storage", storage.Section.Key("MINIO_BUCKET").String())
163168
}
164169
}
170+
171+
func Test_getStorageInheritStorageType(t *testing.T) {
172+
iniStr := `
173+
[storage]
174+
STORAGE_TYPE = minio
175+
`
176+
Cfg, _ = ini.Load([]byte(iniStr))
177+
178+
sec := Cfg.Section("attachment")
179+
storageType := sec.Key("STORAGE_TYPE").MustString("")
180+
storage := getStorage("attachments", storageType, sec)
181+
182+
assert.EqualValues(t, "minio", storage.Type)
183+
}
184+
185+
func Test_getStorageInheritNameSectionType(t *testing.T) {
186+
iniStr := `
187+
[storage.attachments]
188+
STORAGE_TYPE = minio
189+
`
190+
Cfg, _ = ini.Load([]byte(iniStr))
191+
192+
sec := Cfg.Section("attachment")
193+
storageType := sec.Key("STORAGE_TYPE").MustString("")
194+
storage := getStorage("attachments", storageType, sec)
195+
196+
assert.EqualValues(t, "minio", storage.Type)
197+
}

modules/templates/dynamic.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import (
1818
"code.gitea.io/gitea/modules/util"
1919

2020
"gitea.com/macaron/macaron"
21-
"github.com/unknwon/com"
2221
)
2322

2423
var (
@@ -65,7 +64,7 @@ func Mailer() (*texttmpl.Template, *template.Template) {
6564
log.Warn("Unable to check if templates dir %s is a directory. Error: %v", staticDir, err)
6665
}
6766
if isDir {
68-
files, err := com.StatDir(staticDir)
67+
files, err := util.StatDir(staticDir)
6968

7069
if err != nil {
7170
log.Warn("Failed to read %s templates dir. %v", staticDir, err)
@@ -94,7 +93,7 @@ func Mailer() (*texttmpl.Template, *template.Template) {
9493
log.Warn("Unable to check if templates dir %s is a directory. Error: %v", customDir, err)
9594
}
9695
if isDir {
97-
files, err := com.StatDir(customDir)
96+
files, err := util.StatDir(customDir)
9897

9998
if err != nil {
10099
log.Warn("Failed to read %s templates dir. %v", customDir, err)

modules/templates/static.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"code.gitea.io/gitea/modules/util"
2222

2323
"gitea.com/macaron/macaron"
24-
"github.com/unknwon/com"
2524
)
2625

2726
var (
@@ -83,7 +82,7 @@ func NewTemplateFileSystem() templateFileSystem {
8382
log.Warn("Unable to check if templates dir %s is a directory. Error: %v", customDir, err)
8483
}
8584
if isDir {
86-
files, err := com.StatDir(customDir)
85+
files, err := util.StatDir(customDir)
8786

8887
if err != nil {
8988
log.Warn("Failed to read %s templates dir. %v", customDir, err)
@@ -179,7 +178,7 @@ func Mailer() (*texttmpl.Template, *template.Template) {
179178
log.Warn("Failed to check if custom directory %s is a directory. %v", err)
180179
}
181180
if isDir {
182-
files, err := com.StatDir(customDir)
181+
files, err := util.StatDir(customDir)
183182

184183
if err != nil {
185184
log.Warn("Failed to read %s templates dir. %v", customDir, err)

modules/util/path.go

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
package util
66

77
import (
8+
"errors"
89
"os"
10+
"path"
911
"path/filepath"
12+
"strings"
1013
)
1114

1215
// EnsureAbsolutePath ensure that a path is absolute, making it
@@ -70,3 +73,80 @@ func IsExist(path string) (bool, error) {
7073
}
7174
return false, err
7275
}
76+
77+
func statDir(dirPath, recPath string, includeDir, isDirOnly, followSymlinks bool) ([]string, error) {
78+
dir, err := os.Open(dirPath)
79+
if err != nil {
80+
return nil, err
81+
}
82+
defer dir.Close()
83+
84+
fis, err := dir.Readdir(0)
85+
if err != nil {
86+
return nil, err
87+
}
88+
89+
statList := make([]string, 0)
90+
for _, fi := range fis {
91+
if strings.Contains(fi.Name(), ".DS_Store") {
92+
continue
93+
}
94+
95+
relPath := path.Join(recPath, fi.Name())
96+
curPath := path.Join(dirPath, fi.Name())
97+
if fi.IsDir() {
98+
if includeDir {
99+
statList = append(statList, relPath+"/")
100+
}
101+
s, err := statDir(curPath, relPath, includeDir, isDirOnly, followSymlinks)
102+
if err != nil {
103+
return nil, err
104+
}
105+
statList = append(statList, s...)
106+
} else if !isDirOnly {
107+
statList = append(statList, relPath)
108+
} else if followSymlinks && fi.Mode()&os.ModeSymlink != 0 {
109+
link, err := os.Readlink(curPath)
110+
if err != nil {
111+
return nil, err
112+
}
113+
114+
isDir, err := IsDir(link)
115+
if err != nil {
116+
return nil, err
117+
}
118+
if isDir {
119+
if includeDir {
120+
statList = append(statList, relPath+"/")
121+
}
122+
s, err := statDir(curPath, relPath, includeDir, isDirOnly, followSymlinks)
123+
if err != nil {
124+
return nil, err
125+
}
126+
statList = append(statList, s...)
127+
}
128+
}
129+
}
130+
return statList, nil
131+
}
132+
133+
// StatDir gathers information of given directory by depth-first.
134+
// It returns slice of file list and includes subdirectories if enabled;
135+
// it returns error and nil slice when error occurs in underlying functions,
136+
// or given path is not a directory or does not exist.
137+
//
138+
// Slice does not include given path itself.
139+
// If subdirectories is enabled, they will have suffix '/'.
140+
func StatDir(rootPath string, includeDir ...bool) ([]string, error) {
141+
if isDir, err := IsDir(rootPath); err != nil {
142+
return nil, err
143+
} else if !isDir {
144+
return nil, errors.New("not a directory or does not exist: " + rootPath)
145+
}
146+
147+
isIncludeDir := false
148+
if len(includeDir) != 0 {
149+
isIncludeDir = includeDir[0]
150+
}
151+
return statDir(rootPath, "", isIncludeDir, false, false)
152+
}

options/locale/locale_ja-JP.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,7 @@ issues.start_tracking_short=開始
11301130
issues.start_tracking=タイムトラッキングを開始
11311131
issues.start_tracking_history=`が作業を開始 %s`
11321132
issues.tracker_auto_close=タイマーは、この課題がクローズされると自動的に終了します
1133+
issues.tracking_already_started=`<a href="%s">別の課題</a>で既にタイムトラッキングを開始しています!`
11331134
issues.stop_tracking=停止
11341135
issues.stop_tracking_history=`が作業を終了 %s`
11351136
issues.add_time=手で時間を入力

options/locale/locale_tr-TR.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,7 @@ email_notifications.submit=E-posta Tercihlerini Ayarla
653653
654654
[repo]
655655
owner=Sahibi
656+
owner_helper=Bazı organizasyonlar, en çok depo sayısı sınırı nedeniyle açılır menüde görünmeyebilir.
656657
repo_name=Depo İsmi
657658
repo_name_helper=İyi bir depo ismi kısa, akılda kalıcı ve özgün anahtar kelimelerden oluşur.
658659
repo_size=Depo Boyutu

0 commit comments

Comments
 (0)