diff --git a/cleanup.go b/cleanup.go index 35340f5..a1a3a71 100644 --- a/cleanup.go +++ b/cleanup.go @@ -26,8 +26,9 @@ func cleanupOrphanedRepos(config *mirror.RepoPoolConfig, repoPool *mirror.RepoPo } repoDirs := repoPool.RepositoriesDirPath() + defaultRepoDirRoot := mirror.DefaultRepoDir(config.Defaults.Root) - entries, err := os.ReadDir(config.Defaults.Root) + entries, err := os.ReadDir(defaultRepoDirRoot) if err != nil { logger.Error("unable to read root dir for clean up", "err", err) return @@ -38,7 +39,7 @@ func cleanupOrphanedRepos(config *mirror.RepoPoolConfig, repoPool *mirror.RepoPo continue } - fullPath := filepath.Join(config.Defaults.Root, entry.Name()) + fullPath := filepath.Join(defaultRepoDirRoot, entry.Name()) if slices.Contains(repoDirs, fullPath) { continue diff --git a/pkg/mirror/config.go b/pkg/mirror/config.go index e92f23e..3fd27ed 100644 --- a/pkg/mirror/config.go +++ b/pkg/mirror/config.go @@ -125,6 +125,11 @@ func (rpc *RepoPoolConfig) ValidateDefaults() error { return nil } +// DefaultRepoDir returns path of dir where all repositories mirrors are cloned +func DefaultRepoDir(root string) string { + return filepath.Join(root, "repo-mirrors") +} + // ApplyDefaults will add given default config to repository config if where needed func (rpc *RepoPoolConfig) ApplyDefaults() { for i := range rpc.Repositories { diff --git a/pkg/mirror/repository.go b/pkg/mirror/repository.go index dba97bb..faf98f9 100644 --- a/pkg/mirror/repository.go +++ b/pkg/mirror/repository.go @@ -105,7 +105,7 @@ func NewRepository(repoConf RepositoryConfig, envs []string, log *slog.Logger) ( if !strings.HasSuffix(repoDir, ".git") { repoDir += ".git" } - repoDir = filepath.Join(repoConf.Root, repoDir) + repoDir = filepath.Join(DefaultRepoDir(repoConf.Root), repoDir) repo := &Repository{ gitURL: gURL, diff --git a/pkg/mirror/repository_test.go b/pkg/mirror/repository_test.go index 309aa78..6921259 100644 --- a/pkg/mirror/repository_test.go +++ b/pkg/mirror/repository_test.go @@ -37,7 +37,7 @@ func TestNewRepo(t *testing.T) { gitURL: &giturl.URL{Scheme: "scp", User: "user", Host: "host.xz", Path: "path/to", Repo: "repo.git"}, remote: "user@host.xz:path/to/repo.git", root: "/tmp", - dir: "/tmp/repo.git", + dir: "/tmp/repo-mirrors/repo.git", gitGC: "always", interval: 10 * time.Second, auth: &Auth{SSHKeyPath: "/path/to/key", SSHKnownHostsPath: "path/to/host"},