@ -6,7 +6,9 @@ package doctor
import (
import (
"fmt"
"fmt"
"os"
"os/exec"
"os/exec"
"path"
"strings"
"strings"
"code.gitea.io/gitea/models"
"code.gitea.io/gitea/models"
@ -14,6 +16,9 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/repository"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
lru "github.com/hashicorp/golang-lru"
"xorm.io/builder"
"xorm.io/builder"
)
)
@ -75,6 +80,7 @@ func checkUserStarNum(logger log.Logger, autofix bool) error {
func checkEnablePushOptions ( logger log . Logger , autofix bool ) error {
func checkEnablePushOptions ( logger log . Logger , autofix bool ) error {
numRepos := 0
numRepos := 0
numNeedUpdate := 0
numNeedUpdate := 0
if err := iterateRepositories ( func ( repo * models . Repository ) error {
if err := iterateRepositories ( func ( repo * models . Repository ) error {
numRepos ++
numRepos ++
r , err := git . OpenRepository ( repo . RepoPath ( ) )
r , err := git . OpenRepository ( repo . RepoPath ( ) )
@ -114,6 +120,66 @@ func checkEnablePushOptions(logger log.Logger, autofix bool) error {
return nil
return nil
}
}
func checkDaemonExport ( logger log . Logger , autofix bool ) error {
numRepos := 0
numNeedUpdate := 0
cache , err := lru . New ( 512 )
if err != nil {
logger . Critical ( "Unable to create cache: %v" , err )
return err
}
if err := iterateRepositories ( func ( repo * models . Repository ) error {
numRepos ++
if owner , has := cache . Get ( repo . OwnerID ) ; has {
repo . Owner = owner . ( * models . User )
} else {
if err := repo . GetOwner ( ) ; err != nil {
return err
}
cache . Add ( repo . OwnerID , repo . Owner )
}
// Create/Remove git-daemon-export-ok for git-daemon...
daemonExportFile := path . Join ( repo . RepoPath ( ) , ` git-daemon-export-ok ` )
isExist , err := util . IsExist ( daemonExportFile )
if err != nil {
log . Error ( "Unable to check if %s exists. Error: %v" , daemonExportFile , err )
return err
}
isPublic := ! repo . IsPrivate && repo . Owner . Visibility == structs . VisibleTypePublic
if isPublic != isExist {
numNeedUpdate ++
if autofix {
if ! isPublic && isExist {
if err = util . Remove ( daemonExportFile ) ; err != nil {
log . Error ( "Failed to remove %s: %v" , daemonExportFile , err )
}
} else if isPublic && ! isExist {
if f , err := os . Create ( daemonExportFile ) ; err != nil {
log . Error ( "Failed to create %s: %v" , daemonExportFile , err )
} else {
f . Close ( )
}
}
}
}
return nil
} ) ; err != nil {
logger . Critical ( "Unable to checkDaemonExport: %v" , err )
return err
}
if autofix {
logger . Info ( "Updated git-daemon-export-ok files for %d of %d repositories." , numNeedUpdate , numRepos )
} else {
logger . Info ( "Checked %d repositories, %d need updates." , numRepos , numNeedUpdate )
}
return nil
}
func init ( ) {
func init ( ) {
Register ( & Check {
Register ( & Check {
Title : "Check if SCRIPT_TYPE is available" ,
Title : "Check if SCRIPT_TYPE is available" ,
@ -143,4 +209,11 @@ func init() {
Run : checkEnablePushOptions ,
Run : checkEnablePushOptions ,
Priority : 7 ,
Priority : 7 ,
} )
} )
Register ( & Check {
Title : "Check git-daemon-export-ok files" ,
Name : "check-git-daemon-export-ok" ,
IsDefault : false ,
Run : checkDaemonExport ,
Priority : 8 ,
} )
}
}