feat: add repo sync white-path #56
This commit is contained in:
@@ -22,7 +22,8 @@ type RepoConfig struct {
|
||||
SingleFile bool `json:"single_file"` // 单文件模式(直接下载文件而非 sparse-checkout)
|
||||
Proxy string `json:"proxy"` // 代理类型: none, ghproxy, mirror, custom
|
||||
ProxyURL string `json:"proxy_url"` // 自定义代理地址
|
||||
AuthToken string `json:"auth_token"` // 认证 Token
|
||||
AuthToken string `json:"auth_token"` // 认证 Token
|
||||
WhitelistPaths string `json:"whitelist_paths"` // 同步时保留的路径(白名单路径),逗号分隔
|
||||
}
|
||||
|
||||
// TaskConfig 任务配置 RepoConfig+TaskConfig=task.config
|
||||
|
||||
@@ -946,6 +946,9 @@ func (es *ExecutorService) BuildRepoCommand(task *models.Task) (string, string)
|
||||
if config.AuthToken != "" {
|
||||
args = append(args, "--auth-token", config.AuthToken)
|
||||
}
|
||||
if config.WhitelistPaths != "" {
|
||||
args = append(args, "--whitelist-paths", config.WhitelistPaths)
|
||||
}
|
||||
|
||||
return exePath + " " + strings.Join(args, " "), filepath.Dir(exePath)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"io"
|
||||
"os"
|
||||
"path/filepath"
|
||||
)
|
||||
|
||||
// CopyPath copies a file or directory from src to dest
|
||||
func CopyPath(src, dest string) error {
|
||||
info, err := os.Stat(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if info.IsDir() {
|
||||
return copyDir(src, dest)
|
||||
}
|
||||
return CopyFile(src, dest)
|
||||
}
|
||||
|
||||
// CopyFile copies a single file from src to dest
|
||||
func CopyFile(src, dest string) error {
|
||||
srcFile, err := os.Open(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer srcFile.Close()
|
||||
|
||||
if err := os.MkdirAll(filepath.Dir(dest), 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
destFile, err := os.Create(dest)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer destFile.Close()
|
||||
|
||||
if _, err := io.Copy(destFile, srcFile); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
info, err := os.Stat(src)
|
||||
if err == nil {
|
||||
os.Chmod(dest, info.Mode())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func copyDir(src, dest string) error {
|
||||
info, err := os.Stat(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.MkdirAll(dest, info.Mode()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
entries, err := os.ReadDir(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, entry := range entries {
|
||||
srcPath := filepath.Join(src, entry.Name())
|
||||
destPath := filepath.Join(dest, entry.Name())
|
||||
|
||||
if err := CopyPath(srcPath, destPath); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user