Do a fast-fail testing on repository URL before mirroring

To ensure the URL is accessible under good condition to prevent
long blocking on URL resolution without syncing anything.
master
Unknwon 2017-01-31 18:40:38 -05:00
parent 0cfcaca351
commit d293aa9ced
No known key found for this signature in database
GPG Key ID: FB9F411CDD69BEC1
7 changed files with 29 additions and 7 deletions

View File

@ -19,7 +19,7 @@ github.com/go-xorm/core = commit:2fbe2c7
github.com/go-xorm/xorm = commit:445a934
github.com/gogits/chardet = commit:2404f77
github.com/gogits/cron = commit:2fc07a4
github.com/gogits/git-module = commit:df1013f
github.com/gogits/git-module = commit:172cbc2
github.com/gogits/go-gogs-client = commit:98046bb
github.com/gogits/go-libravatar = commit:cd1abbd
github.com/issue9/identicon = commit:d36b545

View File

@ -94,7 +94,7 @@ func checkVersion() {
{"github.com/go-macaron/toolbox", toolbox.Version, "0.1.0"},
{"gopkg.in/ini.v1", ini.Version, "1.8.4"},
{"gopkg.in/macaron.v1", macaron.Version, "1.1.7"},
{"github.com/gogits/git-module", git.Version, "0.4.5"},
{"github.com/gogits/git-module", git.Version, "0.4.6"},
{"github.com/gogits/go-gogs-client", gogs.Version, "0.12.1"},
}
for _, c := range checkers {

2
glide.lock generated
View File

@ -43,7 +43,7 @@ imports:
- name: github.com/gogits/cron
version: 2fc07a4c4f1e3c4d2301c5ed578d5e2c31c70421
- name: github.com/gogits/git-module
version: df1013f8eb4dc70de90bc5597bf560a4b7da802e
version: 172cbc21accbf0085a58fd0832f46a9f694130e8
- name: github.com/gogits/go-gogs-client
version: 98046bb98061fc6baa5bb86359af0b7c300d384a
- name: github.com/gogits/go-libravatar

View File

@ -16,7 +16,7 @@ import (
"github.com/gogits/gogs/modules/setting"
)
const APP_VER = "0.9.128.0131"
const APP_VER = "0.9.129.0131"
func init() {
setting.AppVer = APP_VER

View File

@ -599,7 +599,9 @@ func wikiRemoteURL(remote string) string {
remote = strings.TrimSuffix(remote, ".git")
for _, suffix := range commonWikiURLSuffixes {
wikiURL := remote + suffix
if git.IsRepoURLAccessible(wikiURL) {
if git.IsRepoURLAccessible(git.NetworkOptions{
URL: wikiURL,
}) {
return wikiURL
}
}

View File

@ -13,6 +13,8 @@ import (
"github.com/go-xorm/xorm"
"gopkg.in/ini.v1"
"github.com/gogits/git-module"
"github.com/gogits/gogs/modules/log"
"github.com/gogits/gogs/modules/process"
"github.com/gogits/gogs/modules/setting"
@ -104,6 +106,12 @@ func (m *Mirror) Address() string {
return HandleCloneUserCredentials(m.address, false)
}
// MosaicsAddress returns mirror address from Git repository config with credentials under mosaics.
func (m *Mirror) MosaicsAddress() string {
m.readAddress()
return HandleCloneUserCredentials(m.address, true)
}
// FullAddress returns mirror address from Git repository config.
func (m *Mirror) FullAddress() string {
m.readAddress()
@ -128,11 +136,23 @@ func (m *Mirror) runSync() bool {
wikiPath := m.Repo.WikiPath()
timeout := time.Duration(setting.Git.Timeout.Mirror) * time.Second
// Do a fast-fail testing against on repository URL to ensure it is accessible under
// good condition to prevent long blocking on URL resolution without syncing anything.
if !git.IsRepoURLAccessible(git.NetworkOptions{
URL: m.FullAddress(),
Timeout: 10 * time.Second,
}) {
desc := fmt.Sprintf("Mirror repository URL is not accessible: %s", m.MosaicsAddress())
if err := CreateRepositoryNotice(desc); err != nil {
log.Error(4, "CreateRepositoryNotice: %v", err)
}
return false
}
gitArgs := []string{"remote", "update"}
if m.EnablePrune {
gitArgs = append(gitArgs, "--prune")
}
if _, stderr, err := process.ExecDir(
timeout, repoPath, fmt.Sprintf("Mirror.runSync: %s", repoPath),
"git", gitArgs...); err != nil {

View File

@ -1 +1 @@
0.9.128.0131
0.9.129.0131