Skip to content

Commit 36ec040

Browse files
committed
keep all repo clone dir organised
1 parent 0550084 commit 36ec040

File tree

4 files changed

+10
-4
lines changed

4 files changed

+10
-4
lines changed

cleanup.go

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ func cleanupOrphanedRepos(config *mirror.RepoPoolConfig, repoPool *mirror.RepoPo
2626
}
2727

2828
repoDirs := repoPool.RepositoriesDirPath()
29+
defaultRepoDirRoot := mirror.DefaultRepoDir(config.Defaults.Root)
2930

30-
entries, err := os.ReadDir(config.Defaults.Root)
31+
entries, err := os.ReadDir(defaultRepoDirRoot)
3132
if err != nil {
3233
logger.Error("unable to read root dir for clean up", "err", err)
3334
return
@@ -38,7 +39,7 @@ func cleanupOrphanedRepos(config *mirror.RepoPoolConfig, repoPool *mirror.RepoPo
3839
continue
3940
}
4041

41-
fullPath := filepath.Join(config.Defaults.Root, entry.Name())
42+
fullPath := filepath.Join(defaultRepoDirRoot, entry.Name())
4243

4344
if slices.Contains(repoDirs, fullPath) {
4445
continue

pkg/mirror/config.go

+5
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ func (rpc *RepoPoolConfig) ValidateDefaults() error {
125125
return nil
126126
}
127127

128+
// DefaultRepoDir returns path of dir where all repositories mirrors are cloned
129+
func DefaultRepoDir(root string) string {
130+
return filepath.Join(root, "repo-mirrors")
131+
}
132+
128133
// ApplyDefaults will add given default config to repository config if where needed
129134
func (rpc *RepoPoolConfig) ApplyDefaults() {
130135
for i := range rpc.Repositories {

pkg/mirror/repository.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ func NewRepository(repoConf RepositoryConfig, envs []string, log *slog.Logger) (
105105
if !strings.HasSuffix(repoDir, ".git") {
106106
repoDir += ".git"
107107
}
108-
repoDir = filepath.Join(repoConf.Root, repoDir)
108+
repoDir = filepath.Join(DefaultRepoDir(repoConf.Root), repoDir)
109109

110110
repo := &Repository{
111111
gitURL: gURL,

pkg/mirror/repository_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ func TestNewRepo(t *testing.T) {
3737
gitURL: &giturl.URL{Scheme: "scp", User: "user", Host: "host.xz", Path: "path/to", Repo: "repo.git"},
3838
remote: "[email protected]:path/to/repo.git",
3939
root: "/tmp",
40-
dir: "/tmp/repo.git",
40+
dir: "/tmp/repo-mirrors/repo.git",
4141
gitGC: "always",
4242
interval: 10 * time.Second,
4343
auth: &Auth{SSHKeyPath: "/path/to/key", SSHKnownHostsPath: "path/to/host"},

0 commit comments

Comments
 (0)