mirror of
https://github.com/gogs/gogs.git
synced 2025-05-24 00:12:26 +00:00
models/repo_editor: ignore copying files with '.git/' path prefix (#5558)
This commit is contained in:
parent
8c8c37a66b
commit
1f11c1f71a
@ -13,6 +13,7 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/Unknwon/com"
|
"github.com/Unknwon/com"
|
||||||
@ -467,14 +468,19 @@ func (repo *Repository) UploadRepoFiles(doer *User, opts UploadRepoFileOptions)
|
|||||||
dirPath := path.Join(localPath, opts.TreePath)
|
dirPath := path.Join(localPath, opts.TreePath)
|
||||||
os.MkdirAll(dirPath, os.ModePerm)
|
os.MkdirAll(dirPath, os.ModePerm)
|
||||||
|
|
||||||
// Copy uploaded files into repository.
|
// Copy uploaded files into repository
|
||||||
for _, upload := range uploads {
|
for _, upload := range uploads {
|
||||||
tmpPath := upload.LocalPath()
|
tmpPath := upload.LocalPath()
|
||||||
targetPath := path.Join(dirPath, upload.Name)
|
|
||||||
if !com.IsFile(tmpPath) {
|
if !com.IsFile(tmpPath) {
|
||||||
continue
|
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 {
|
if err = com.Copy(tmpPath, targetPath); err != nil {
|
||||||
return fmt.Errorf("copy: %v", err)
|
return fmt.Errorf("copy: %v", err)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user