Skip to content

Commit 9815e9d

Browse files
committed
Merge branch 'master' into allow-block_list_migrate-mirror_8040
2 parents bb5ce58 + 742e21a commit 9815e9d

File tree

29 files changed

+391
-101
lines changed

29 files changed

+391
-101
lines changed

cmd/dump.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323

2424
"gitea.com/macaron/session"
2525
archiver "github.com/mholt/archiver/v3"
26-
"github.com/unknwon/com"
2726
"github.com/urfave/cli"
2827
)
2928

@@ -306,7 +305,11 @@ func runDump(ctx *cli.Context) error {
306305
log.Info("Custom dir %s doesn't exist, skipped", setting.CustomPath)
307306
}
308307

309-
if com.IsExist(setting.AppDataPath) {
308+
isExist, err := util.IsExist(setting.AppDataPath)
309+
if err != nil {
310+
log.Error("Unable to check if %s exists. Error: %v", setting.AppDataPath, err)
311+
}
312+
if isExist {
310313
log.Info("Packing data directory...%s", setting.AppDataPath)
311314

312315
var excludes []string
@@ -349,9 +352,15 @@ func runDump(ctx *cli.Context) error {
349352
// yet or not.
350353
if ctx.IsSet("skip-log") && ctx.Bool("skip-log") {
351354
log.Info("Skip dumping log files")
352-
} else if com.IsExist(setting.LogRootPath) {
353-
if err := addRecursive(w, "log", setting.LogRootPath, verbose); err != nil {
354-
fatal("Failed to include log: %v", err)
355+
} else {
356+
isExist, err := util.IsExist(setting.LogRootPath)
357+
if err != nil {
358+
log.Error("Unable to check if %s exists. Error: %v", setting.LogRootPath, err)
359+
}
360+
if isExist {
361+
if err := addRecursive(w, "log", setting.LogRootPath, verbose); err != nil {
362+
fatal("Failed to include log: %v", err)
363+
}
355364
}
356365
}
357366

cmd/web.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ import (
1616
"code.gitea.io/gitea/modules/graceful"
1717
"code.gitea.io/gitea/modules/log"
1818
"code.gitea.io/gitea/modules/setting"
19+
"code.gitea.io/gitea/modules/util"
1920
"code.gitea.io/gitea/routers"
2021
"code.gitea.io/gitea/routers/routes"
2122

2223
context2 "github.com/gorilla/context"
23-
"github.com/unknwon/com"
2424
"github.com/urfave/cli"
2525
"golang.org/x/crypto/acme/autocert"
2626
ini "gopkg.in/ini.v1"
@@ -188,7 +188,11 @@ func setPort(port string) error {
188188
default:
189189
// Save LOCAL_ROOT_URL if port changed
190190
cfg := ini.Empty()
191-
if com.IsFile(setting.CustomConf) {
191+
isFile, err := util.IsFile(setting.CustomConf)
192+
if err != nil {
193+
log.Fatal("Unable to check if %s is a file", err)
194+
}
195+
if isFile {
192196
// Keeps custom settings if there is already something.
193197
if err := cfg.Append(setting.CustomConf); err != nil {
194198
return fmt.Errorf("Failed to load custom conf '%s': %v", setting.CustomConf, err)

contrib/environment-to-ini/environment-to-ini.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import (
1212

1313
"code.gitea.io/gitea/modules/log"
1414
"code.gitea.io/gitea/modules/setting"
15+
"code.gitea.io/gitea/modules/util"
1516

16-
"github.com/unknwon/com"
1717
"github.com/urfave/cli"
1818
ini "gopkg.in/ini.v1"
1919
)
@@ -97,7 +97,11 @@ func runEnvironmentToIni(c *cli.Context) error {
9797
setting.SetCustomPathAndConf(providedCustom, providedConf, providedWorkPath)
9898

9999
cfg := ini.Empty()
100-
if com.IsFile(setting.CustomConf) {
100+
isFile, err := util.IsFile(setting.CustomConf)
101+
if err != nil {
102+
log.Fatal("Unable to check if %s is a file. Error: %v", setting.CustomConf, err)
103+
}
104+
if isFile {
101105
if err := cfg.Append(setting.CustomConf); err != nil {
102106
log.Fatal("Failed to load custom conf '%s': %v", setting.CustomConf, err)
103107
}
@@ -145,7 +149,7 @@ func runEnvironmentToIni(c *cli.Context) error {
145149
if len(destination) == 0 {
146150
destination = setting.CustomConf
147151
}
148-
err := cfg.SaveTo(destination)
152+
err = cfg.SaveTo(destination)
149153
if err != nil {
150154
return err
151155
}

docs/content/doc/usage/fail2ban-setup.en-us.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@ menu:
1515

1616
# Fail2ban setup to block users after failed login attempts
1717

18-
**Remember that fail2ban is powerful and can cause lots of issues if you do it incorrectly, so make
18+
**Remember that fail2ban is powerful and can cause lots of issues if you do it incorrectly, so make
1919
sure to test this before relying on it so you don't lock yourself out.**
2020

21-
Gitea returns an HTTP 200 for bad logins in the web logs, but if you have logging options on in
22-
`app.ini`, then you should be able to go off of `log/gitea.log`, which gives you something like this
21+
Gitea returns an HTTP 200 for bad logins in the web logs, but if you have logging options on in
22+
`app.ini`, then you should be able to go off of `log/gitea.log`, which gives you something like this
2323
on a bad authentication:
2424

2525
```log
@@ -41,14 +41,14 @@ Add our jail in `/etc/fail2ban/jail.d/gitea.conf`:
4141
[gitea]
4242
enabled = true
4343
filter = gitea
44-
logpath = /home/git/gitea/log/gitea.log
44+
logpath = /var/lib/gitea/log/gitea.log
4545
maxretry = 10
4646
findtime = 3600
4747
bantime = 900
4848
action = iptables-allports
4949
```
5050

51-
If you're using Docker, you'll also need to add an additional jail to handle the **FORWARD**
51+
If you're using Docker, you'll also need to add an additional jail to handle the **FORWARD**
5252
chain in **iptables**. Configure it in `/etc/fail2ban/jail.d/gitea-docker.conf`:
5353

5454
```ini
@@ -62,14 +62,14 @@ bantime = 900
6262
action = iptables-allports[chain="FORWARD"]
6363
```
6464

65-
Then simply run `service fail2ban restart` to apply your changes. You can check to see if
65+
Then simply run `service fail2ban restart` to apply your changes. You can check to see if
6666
fail2ban has accepted your configuration using `service fail2ban status`.
6767

68-
Make sure and read up on fail2ban and configure it to your needs, this bans someone
68+
Make sure and read up on fail2ban and configure it to your needs, this bans someone
6969
for **15 minutes** (from all ports) when they fail authentication 10 times in an hour.
7070

7171
If you run Gitea behind a reverse proxy with Nginx (for example with Docker), you need to add
72-
this to your Nginx configuration so that IPs don't show up as 127.0.0.1:
72+
this to your Nginx configuration so that IPs don't show up as 127.0.0.1:
7373

7474
```
7575
proxy_set_header X-Real-IP $remote_addr;

models/repo.go

Lines changed: 46 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ func loadRepoConfig() {
7474
log.Fatal("Failed to get %s files: %v", t, err)
7575
}
7676
customPath := path.Join(setting.CustomPath, "options", t)
77-
if com.IsDir(customPath) {
77+
isDir, err := util.IsDir(customPath)
78+
if err != nil {
79+
log.Fatal("Failed to get custom %s files: %v", t, err)
80+
}
81+
if isDir {
7882
customFiles, err := com.StatDir(customPath)
7983
if err != nil {
8084
log.Fatal("Failed to get custom %s files: %v", t, err)
@@ -1004,7 +1008,11 @@ func isRepositoryExist(e Engine, u *User, repoName string) (bool, error) {
10041008
OwnerID: u.ID,
10051009
LowerName: strings.ToLower(repoName),
10061010
})
1007-
return has && com.IsDir(RepoPath(u.Name, repoName)), err
1011+
if err != nil {
1012+
return false, err
1013+
}
1014+
isDir, err := util.IsDir(RepoPath(u.Name, repoName))
1015+
return has && isDir, err
10081016
}
10091017

10101018
// IsRepositoryExist returns true if the repository with given name under user has already existed.
@@ -1078,7 +1086,12 @@ func CheckCreateRepository(doer, u *User, name string, overwriteOrAdopt bool) er
10781086
return ErrRepoAlreadyExist{u.Name, name}
10791087
}
10801088

1081-
if !overwriteOrAdopt && com.IsExist(RepoPath(u.Name, name)) {
1089+
isExist, err := util.IsExist(RepoPath(u.Name, name))
1090+
if err != nil {
1091+
log.Error("Unable to check if %s exists. Error: %v", RepoPath(u.Name, name), err)
1092+
return err
1093+
}
1094+
if !overwriteOrAdopt && isExist {
10821095
return ErrRepoFilesAlreadyExist{u.Name, name}
10831096
}
10841097
return nil
@@ -1110,7 +1123,11 @@ func GetRepoInitFile(tp, name string) ([]byte, error) {
11101123

11111124
// Use custom file when available.
11121125
customPath := path.Join(setting.CustomPath, relPath)
1113-
if com.IsFile(customPath) {
1126+
isFile, err := util.IsFile(customPath)
1127+
if err != nil {
1128+
log.Error("Unable to check if %s is a file. Error: %v", customPath, err)
1129+
}
1130+
if isFile {
11141131
return ioutil.ReadFile(customPath)
11151132
}
11161133

@@ -1156,7 +1173,12 @@ func CreateRepository(ctx DBContext, doer, u *User, repo *Repository, overwriteO
11561173
}
11571174

11581175
repoPath := RepoPath(u.Name, repo.Name)
1159-
if !overwriteOrAdopt && com.IsExist(repoPath) {
1176+
isExist, err := util.IsExist(repoPath)
1177+
if err != nil {
1178+
log.Error("Unable to check if %s exists. Error: %v", repoPath, err)
1179+
return err
1180+
}
1181+
if !overwriteOrAdopt && isExist {
11601182
log.Error("Files already exist in %s and we are not going to adopt or delete.", repoPath)
11611183
return ErrRepoFilesAlreadyExist{
11621184
Uname: u.Name,
@@ -1408,7 +1430,12 @@ func TransferOwnership(doer *User, newOwnerName string, repo *Repository) error
14081430

14091431
// Rename remote wiki repository to new path and delete local copy.
14101432
wikiPath := UncycloPath(oldOwner.Name, repo.Name)
1411-
if com.IsExist(wikiPath) {
1433+
isExist, err := util.IsExist(wikiPath)
1434+
if err != nil {
1435+
log.Error("Unable to check if %s exists. Error: %v", wikiPath, err)
1436+
return err
1437+
}
1438+
if isExist {
14121439
if err = os.Rename(wikiPath, UncycloPath(newOwner.Name, repo.Name)); err != nil {
14131440
return fmt.Errorf("rename repository wiki: %v", err)
14141441
}
@@ -1451,7 +1478,12 @@ func ChangeRepositoryName(doer *User, repo *Repository, newRepoName string) (err
14511478
}
14521479

14531480
wikiPath := repo.UncycloPath()
1454-
if com.IsExist(wikiPath) {
1481+
isExist, err := util.IsExist(wikiPath)
1482+
if err != nil {
1483+
log.Error("Unable to check if %s exists. Error: %v", wikiPath, err)
1484+
return err
1485+
}
1486+
if isExist {
14551487
if err = os.Rename(wikiPath, UncycloPath(repo.Owner.Name, newRepoName)); err != nil {
14561488
return fmt.Errorf("rename repository wiki: %v", err)
14571489
}
@@ -1528,11 +1560,16 @@ func updateRepository(e Engine, repo *Repository, visibilityChanged bool) (err e
15281560

15291561
// Create/Remove git-daemon-export-ok for git-daemon...
15301562
daemonExportFile := path.Join(repo.RepoPath(), `git-daemon-export-ok`)
1531-
if repo.IsPrivate && com.IsExist(daemonExportFile) {
1563+
isExist, err := util.IsExist(daemonExportFile)
1564+
if err != nil {
1565+
log.Error("Unable to check if %s exists. Error: %v", daemonExportFile, err)
1566+
return err
1567+
}
1568+
if repo.IsPrivate && isExist {
15321569
if err = util.Remove(daemonExportFile); err != nil {
15331570
log.Error("Failed to remove %s: %v", daemonExportFile, err)
15341571
}
1535-
} else if !repo.IsPrivate && !com.IsExist(daemonExportFile) {
1572+
} else if !repo.IsPrivate && !isExist {
15361573
if f, err := os.Create(daemonExportFile); err != nil {
15371574
log.Error("Failed to create %s: %v", daemonExportFile, err)
15381575
} else {

models/ssh_key.go

Lines changed: 32 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -736,11 +736,18 @@ func rewriteAllPublicKeys(e Engine) error {
736736
}
737737
}()
738738

739-
if setting.SSH.AuthorizedKeysBackup && com.IsExist(fPath) {
740-
bakPath := fmt.Sprintf("%s_%d.gitea_bak", fPath, time.Now().Unix())
741-
if err = com.Copy(fPath, bakPath); err != nil {
739+
if setting.SSH.AuthorizedKeysBackup {
740+
isExist, err := util.IsExist(fPath)
741+
if err != nil {
742+
log.Error("Unable to check if %s exists. Error: %v", fPath, err)
742743
return err
743744
}
745+
if isExist {
746+
bakPath := fmt.Sprintf("%s_%d.gitea_bak", fPath, time.Now().Unix())
747+
if err = com.Copy(fPath, bakPath); err != nil {
748+
return err
749+
}
750+
}
744751
}
745752

746753
if err := regeneratePublicKeys(e, t); err != nil {
@@ -765,7 +772,12 @@ func regeneratePublicKeys(e Engine, t io.StringWriter) error {
765772
}
766773

767774
fPath := filepath.Join(setting.SSH.RootPath, "authorized_keys")
768-
if com.IsExist(fPath) {
775+
isExist, err := util.IsExist(fPath)
776+
if err != nil {
777+
log.Error("Unable to check if %s exists. Error: %v", fPath, err)
778+
return err
779+
}
780+
if isExist {
769781
f, err := os.Open(fPath)
770782
if err != nil {
771783
return err
@@ -1206,11 +1218,18 @@ func rewriteAllPrincipalKeys(e Engine) error {
12061218
os.Remove(tmpPath)
12071219
}()
12081220

1209-
if setting.SSH.AuthorizedPrincipalsBackup && com.IsExist(fPath) {
1210-
bakPath := fmt.Sprintf("%s_%d.gitea_bak", fPath, time.Now().Unix())
1211-
if err = com.Copy(fPath, bakPath); err != nil {
1221+
if setting.SSH.AuthorizedPrincipalsBackup {
1222+
isExist, err := util.IsExist(fPath)
1223+
if err != nil {
1224+
log.Error("Unable to check if %s exists. Error: %v", fPath, err)
12121225
return err
12131226
}
1227+
if isExist {
1228+
bakPath := fmt.Sprintf("%s_%d.gitea_bak", fPath, time.Now().Unix())
1229+
if err = com.Copy(fPath, bakPath); err != nil {
1230+
return err
1231+
}
1232+
}
12141233
}
12151234

12161235
if err := regeneratePrincipalKeys(e, t); err != nil {
@@ -1249,7 +1268,12 @@ func regeneratePrincipalKeys(e Engine, t io.StringWriter) error {
12491268
}
12501269

12511270
fPath := filepath.Join(setting.SSH.RootPath, authorizedPrincipalsFile)
1252-
if com.IsExist(fPath) {
1271+
isExist, err := util.IsExist(fPath)
1272+
if err != nil {
1273+
log.Error("Unable to check if %s exists. Error: %v", fPath, err)
1274+
return err
1275+
}
1276+
if isExist {
12531277
f, err := os.Open(fPath)
12541278
if err != nil {
12551279
return err

models/upload.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ import (
1212
"os"
1313
"path"
1414

15+
"code.gitea.io/gitea/modules/log"
1516
"code.gitea.io/gitea/modules/setting"
1617
"code.gitea.io/gitea/modules/util"
1718

1819
gouuid "github.com/google/uuid"
19-
"github.com/unknwon/com"
2020
)
2121

2222
// ____ ___ .__ .___ ___________.___.__
@@ -126,7 +126,11 @@ func DeleteUploads(uploads ...*Upload) (err error) {
126126

127127
for _, upload := range uploads {
128128
localPath := upload.LocalPath()
129-
if !com.IsFile(localPath) {
129+
isFile, err := util.IsFile(localPath)
130+
if err != nil {
131+
log.Error("Unable to check if %s is a file. Error: %v", localPath, err)
132+
}
133+
if !isFile {
130134
continue
131135
}
132136

models/wiki.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import (
99
"path/filepath"
1010
"strings"
1111

12-
"github.com/unknwon/com"
12+
"code.gitea.io/gitea/modules/log"
13+
"code.gitea.io/gitea/modules/util"
1314
)
1415

1516
// UncycloCloneLink returns clone URLs of repository wiki.
@@ -29,5 +30,9 @@ func (repo *Repository) UncycloPath() string {
2930

3031
// HasUncyclo returns true if repository has wiki.
3132
func (repo *Repository) HasUncyclo() bool {
32-
return com.IsDir(repo.UncycloPath())
33+
isDir, err := util.IsDir(repo.UncycloPath())
34+
if err != nil {
35+
log.Error("Unable to check if %s is a directory: %v", repo.UncycloPath(), err)
36+
}
37+
return isDir
3338
}

0 commit comments

Comments
 (0)