Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions cleanup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
5 changes: 5 additions & 0 deletions pkg/mirror/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion pkg/mirror/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pkg/mirror/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
Loading