瀏覽代碼

[models/repo_editor] Isolated annexSync function

- Moved annex sync calling and error reporting code to its own function
in models/models_gin.go.
- Moved check for indexing setting into StartIndexing function to avoid
having the check wherever the StartIndexing call is is made.
- Removed call to RemoveAllWithNotice since DeleteUploads() takes care
of the deletion.
Achilleas Koutsou 6 年之前
父節點
當前提交
3b2dea1918
共有 2 個文件被更改,包括 18 次插入16 次删除
  1. 14 0
      models/models_gin.go
  2. 4 16
      models/repo_editor.go

+ 14 - 0
models/models_gin.go

@@ -14,6 +14,9 @@ import (
 // StartIndexing sends an indexing request to the configured indexing service
 // for a repository.
 func StartIndexing(user, owner *User, repo *Repository) {
+	if !setting.Search.Do {
+		return
+	}
 	var ireq struct{ RepoID, RepoPath string }
 	ireq.RepoID = fmt.Sprintf("%d", repo.ID)
 	ireq.RepoPath = repo.FullName()
@@ -63,3 +66,14 @@ func annexAdd(path string) {
 		log.Error(1, "Annex add failed with error: %v (%s)", err, msg)
 	}
 }
+
+func annexSync(path string) error {
+	log.Trace("Synchronising annexed data")
+	if msg, err := gannex.ASync(path, "--content"); err != nil {
+		// TODO: This will also DOWNLOAD content, which is unnecessary for a simple upload
+		// TODO: Use gin-cli upload function instead
+		log.Error(1, "Annex sync failed: %v (%s)", err, msg)
+		return fmt.Errorf("git annex sync --content [%s]", path)
+	}
+	return nil
+}

+ 4 - 16
models/repo_editor.go

@@ -18,11 +18,9 @@ import (
 
 	"github.com/Unknwon/com"
 	gouuid "github.com/satori/go.uuid"
-	log "gopkg.in/clog.v1"
 
 	git "github.com/G-Node/git-module"
 
-	gannex "github.com/G-Node/go-annex"
 	"github.com/G-Node/gogs/models/errors"
 	"github.com/G-Node/gogs/pkg/process"
 	"github.com/G-Node/gogs/pkg/setting"
@@ -521,20 +519,10 @@ func (repo *Repository) UploadRepoFiles(doer *User, opts UploadRepoFileOptions)
 		return fmt.Errorf("git push origin %s: %v", opts.NewBranch, err)
 	}
 
-	// GIN START
-	log.Trace("Synchronising annexed data")
-	if msg, err := gannex.ASync(localPath, "--content"); err != nil {
-		// TODO: This will also DOWNLOAD content, which is unnecessary for a simple upload
-		// TODO: Use gin-cli upload function instead
-		log.Error(1, "Annex sync failed: %v (%s)", err, msg)
-	}
-
-	annexUninit(localPath)
-	// Indexing support
-	if setting.Search.Do {
-		StartIndexing(doer, repo.MustOwner(), repo)
+	if err := annexSync(localPath); err != nil { // Run full annex sync
+		return err
 	}
-	RemoveAllWithNotice("Cleaning out after upload", localPath)
-	// GIN END
+	annexUninit(localPath)                      // Uninitialise annex to prepare for deletion
+	StartIndexing(doer, repo.MustOwner(), repo) // Index the new data
 	return DeleteUploads(uploads...)
 }