From f76de688455154b76c0dc7d206302ee8364281b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=BD=D0=B0=D0=B1?= Date: Wed, 19 Aug 2020 00:21:18 +0200 Subject: [PATCH] Also create/delete git-daemon-export-ok in gitsrht-update-hook --- gitsrht-update-hook/post-update.go | 14 ++++++++++++++ gitsrht/types/__init__.py | 1 + 2 files changed, 15 insertions(+) diff --git a/gitsrht-update-hook/post-update.go b/gitsrht-update-hook/post-update.go index 357ebf6..1349bd5 100644 --- a/gitsrht-update-hook/post-update.go +++ b/gitsrht-update-hook/post-update.go @@ -6,6 +6,7 @@ import ( "fmt" "log" "os" + "path" "strconv" "strings" "syscall" @@ -143,6 +144,18 @@ func parseUpdatables() (*string, *string) { return desc, vis } +// Must match gitsrht/types/__init__.py#update_visibility() +func updateRepoVisibility(repoPath string, visibility string) { + daemonPath := path.Join(repoPath, "git-daemon-export-ok") + shouldExist := visibility == "public" || visibility == "unlisted" + + if shouldExist { + os.Create(daemonPath) + } else { + os.Remove(daemonPath) + } +} + func postUpdate() { var context PushContext refs := os.Args[1:] @@ -190,6 +203,7 @@ func postUpdate() { if err != nil { logger.Fatalf("Failed to fetch info from database: %v", err) } + updateRepoVisibility(context.Repo.Path, dbinfo.Visibility) redisHost, ok := config.Get("sr.ht", "redis-host") if !ok { diff --git a/gitsrht/types/__init__.py b/gitsrht/types/__init__.py index 218bcbe..c9f6967 100644 --- a/gitsrht/types/__init__.py +++ b/gitsrht/types/__init__.py @@ -22,6 +22,7 @@ class Redirect(Base, BaseRedirectMixin): class Repository(Base, BaseRepositoryMixin): _git_repo = None + # Must match gitsrht-update-hook/post-update.go#updateRepoVisibility() def update_visibility(self): if not os.path.exists(self.path): # Repo dir not initialized yet -- 2.38.4