Home

horcrux @main - refs - log -
-
https://git.jolheiser.com/horcrux.git
Split your source across forges
tree log patch
run sync in a goroutine Signed-off-by: jolheiser <git@jolheiser.com>
Signature
-----BEGIN SSH SIGNATURE----- U1NIU0lHAAAAAQAAADMAAAALc3NoLWVkMjU1MTkAAAAgBTEvCQk6VqUAdN2RuH6bj1dNkY oOpbPWj+jw4ua1B1cAAAADZ2l0AAAAAAAAAAZzaGE1MTIAAABTAAAAC3NzaC1lZDI1NTE5 AAAAQPneJJqCoKiCe8IoNVHcUwkRIspitELRye7yVErvv4khrBURkofY5vLJ9HTjqYZTZf bchUuQlj6LoQTZxfeK8Qg= -----END SSH SIGNATURE-----
jolheiser <git@jolheiser.com>
2 weeks ago
1 changed files, 22 additions(+), 20 deletions(-)
main.go
M main.gomain.go
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
diff --git a/main.go b/main.go
index 8bd5def46b511ba0cab9a77d0c73e52f3a2c853d..148dbd1353c1b8fcd95dc4dba1aabf8364ecfc43 100644
--- a/main.go
+++ b/main.go
@@ -61,31 +61,33 @@ 	go func() {
 		for {
 			slog.Debug("running sync...")
 			for _, r := range config.Repos {
-
-				// Check if we need to clone first
-				repoPath := filepath.Join(config.Storage, r.Name)
-				_, err := os.Stat(repoPath)
-				if err != nil {
-					if errors.Is(err, os.ErrNotExist) {
-						if err := git(config.Storage, "clone", "--mirror", r.Source, r.Name); err != nil {
-							slog.Error("could not clone repo", slog.String("repo", r.Source), slog.Any("err", err))
+				go func(r RepoConfig) {
+					// Check if we need to clone first
+					repoPath := filepath.Join(config.Storage, r.Name)
+					_, err := os.Stat(repoPath)
+					if err != nil {
+						if errors.Is(err, os.ErrNotExist) {
+							if err := git(config.Storage, "clone", "--mirror", r.Source, r.Name); err != nil {
+								slog.Error("could not clone repo", slog.String("repo", r.Source), slog.Any("err", err))
+							}
+						} else {
+							slog.Error("could not stat repo path", slog.Any("err", err))
 						}
-					} else {
-						slog.Error("could not stat repo path", slog.Any("err", err))
 					}
-				}
 
-				// Update from remote
-				if err := git(repoPath, "remote", "update", "--prune"); err != nil {
-					slog.Error("could not update repo", slog.String("repo", r.Source), slog.Any("err", err))
-				}
+					// Update from remote
+					if err := git(repoPath, "remote", "update", "--prune"); err != nil {
+						slog.Error("could not update repo", slog.String("repo", r.Source), slog.Any("err", err))
+					}
 
-				// Push
-				for _, dest := range r.Dest {
-					if err := git(repoPath, "push", "--mirror", "--force", dest); err != nil {
-						slog.Error("could not push repo", slog.String("repo", r.Source), slog.String("dest", dest), slog.Any("err", err))
+					// Push
+					for _, dest := range r.Dest {
+						slog.Debug("syncing repo", slog.String("repo", r.Source), slog.String("dest", dest))
+						if err := git(repoPath, "push", "--mirror", "--force", dest); err != nil {
+							slog.Error("could not push repo", slog.String("repo", r.Source), slog.String("dest", dest), slog.Any("err", err))
+						}
 					}
-				}
+				}(r)
 			}
 			<-ticker.C
 		}