From 4ae1a22fecd8b9e1d1e3613edfca0c4e001d4363 Mon Sep 17 00:00:00 2001 From: Runxi Yu Date: Sun, 6 Apr 2025 01:37:57 +0800 Subject: Ensure server is ready before Run() --- server.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/server.go b/server.go index 8c14e3e..fdedf3c 100644 --- a/server.go +++ b/server.go @@ -45,6 +45,8 @@ type Server struct { templates *template.Template ircBot *irc.Bot + + ready bool } func (s *Server) Setup() { @@ -63,14 +65,20 @@ func (s *Server) Setup() { "forge_version": version, // Some other ones are populated after config parsing } -} -func (s *Server) Run() { misc.NoneOrPanic(s.loadTemplates()) misc.NoneOrPanic(misc.DeployBinary(misc.FirstOrPanic(embeddedResourcesFS.Open("git2d/git2d")), s.config.Git.DaemonPath)) misc.NoneOrPanic(misc.DeployBinary(misc.FirstOrPanic(embeddedResourcesFS.Open("hookc/hookc")), filepath.Join(s.config.Hooks.Execs, "pre-receive"))) misc.NoneOrPanic(os.Chmod(filepath.Join(s.config.Hooks.Execs, "pre-receive"), 0o755)) + s.ready = true +} + +func (s *Server) Run() error { + if !s.ready { + return errors.New("not ready") + } + // Launch Git2D go func() { cmd := exec.Command(s.config.Git.DaemonPath, s.config.Git.Socket) //#nosec G204 -- cgit v1.2.3