Jelajahi Sumber

models/repo_editor: ignore copying files with '.git/' path prefix

Yoginth 7 tahun lalu
induk
melakukan
b76c7bf1a1
1 mengubah file dengan 9 tambahan dan 2 penghapusan
  1. 9 2
      models/repo_editor.go

+ 9 - 2
models/repo_editor.go

@@ -19,6 +19,7 @@ import (
 	"os/exec"
 	"path"
 	"path/filepath"
+	"strings"
 	"time"
 
 	"github.com/Unknwon/com"
@@ -444,14 +445,20 @@ func (repo *Repository) UploadRepoFiles(doer *User, opts UploadRepoFileOptions)
 	dirPath := path.Join(localPath, opts.TreePath)
 	os.MkdirAll(dirPath, os.ModePerm)
 
-	// Copy uploaded files into repository.
+	// Copy uploaded files into repository
 	for _, upload := range uploads {
 		tmpPath := upload.LocalPath()
-		targetPath := path.Join(dirPath, upload.Name)
 		if !com.IsFile(tmpPath) {
 			continue
 		}
 
+		// Prevent copying files into .git directory
+		if strings.HasPrefix(upload.Name, ".git/") {
+			continue
+		}
+
+		targetPath := path.Join(dirPath, upload.Name)
+
 		if err = com.Copy(tmpPath, targetPath); err != nil {
 			return fmt.Errorf("copy: %v", err)
 		}