Skip to content

Commit

Permalink
models/repo_editor: ignore copying files with '.git/' path prefix (go…
Browse files Browse the repository at this point in the history
  • Loading branch information
unknwon authored and crohr committed Jan 31, 2019
1 parent 5104892 commit c7578c8
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions models/repo_editor.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"os/exec"
"path"
"path/filepath"
"strings"
"time"

"github.com/Unknwon/com"
Expand Down Expand Up @@ -467,14 +468,19 @@ 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, see https://github.com/gogs/gogs/issues/5558.
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)
}
Expand Down

0 comments on commit c7578c8

Please sign in to comment.