1
0
镜像自地址 https://github.com/tuna/tunasync.git 已同步 2025-12-09 16:06:47 +00:00

Support nested mirror config

这个提交包含在:
Miao Wang
2020-03-29 00:24:58 +08:00
父节点 d10387e40b
当前提交 7a9895350b
共有 5 个文件被更改,包括 225 次插入5 次删除

查看文件

@@ -6,6 +6,7 @@ import (
"path/filepath"
"github.com/BurntSushi/toml"
"github.com/imdario/mergo"
)
type providerEnum uint8
@@ -41,7 +42,8 @@ type Config struct {
BtrfsSnapshot btrfsSnapshotConfig `toml:"btrfs_snapshot"`
Docker dockerConfig `toml:"docker"`
Include includeConfig `toml:"include"`
Mirrors []mirrorConfig `toml:"mirrors"`
MirrorsConf []mirrorConfig `toml:"mirrors"`
Mirrors []mirrorConfig
}
type globalConfig struct {
@@ -117,6 +119,7 @@ type mirrorConfig struct {
Interval int `toml:"interval"`
Retry int `toml:"retry"`
MirrorDir string `toml:"mirror_dir"`
MirrorSubDir string `toml:"mirror_subdir"`
LogDir string `toml:"log_dir"`
Env map[string]string `toml:"env"`
Role string `toml:"role"`
@@ -148,6 +151,8 @@ type mirrorConfig struct {
DockerOptions []string `toml:"docker_options"`
SnapshotPath string `toml:"snapshot_path"`
ChildMirrors []mirrorConfig `toml:"mirrors"`
}
// LoadConfig loads configuration
@@ -174,9 +179,36 @@ func LoadConfig(cfgFile string) (*Config, error) {
logger.Errorf(err.Error())
return nil, err
}
cfg.Mirrors = append(cfg.Mirrors, incMirCfg.Mirrors...)
cfg.MirrorsConf = append(cfg.MirrorsConf, incMirCfg.Mirrors...)
}
}
for _, m := range cfg.MirrorsConf {
if err := recursiveMirrors(cfg, nil, m); err != nil {
return nil, err;
}
}
return cfg, nil
}
func recursiveMirrors(cfg *Config, parent *mirrorConfig, mirror mirrorConfig) error {
var curMir mirrorConfig;
if parent != nil {
curMir = *parent;
}
curMir.ChildMirrors = nil;
if err := mergo.Merge(&curMir, mirror, mergo.WithOverride); err != nil {
return err;
}
if mirror.ChildMirrors == nil {
cfg.Mirrors = append(cfg.Mirrors, curMir);
} else {
for _, m := range mirror.ChildMirrors {
if err := recursiveMirrors(cfg, &curMir, m); err != nil {
return err;
}
}
}
return nil;
}