Parcourir la source

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.
Unknwon il y a 8 ans
Parent
commit
d293aa9ced
7 fichiers modifiés avec 29 ajouts et 7 suppressions
  1. 1 1
      .gopmfile
  2. 1 1
      cmd/web.go
  3. 1 1
      glide.lock
  4. 1 1
      gogs.go
  5. 3 1
      models/repo.go
  6. 21 1
      models/repo_mirror.go
  7. 1 1
      templates/.VERSION

+ 1 - 1
.gopmfile

@@ -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

+ 1 - 1
cmd/web.go

@@ -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 {

+ 1 - 1
glide.lock

@@ -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

+ 1 - 1
gogs.go

@@ -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

+ 3 - 1
models/repo.go

@@ -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
 		}
 	}

+ 21 - 1
models/repo_mirror.go

@@ -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 {

+ 1 - 1
templates/.VERSION

@@ -1 +1 @@
-0.9.128.0131
+0.9.129.0131