From 7779c7ff0c010537d9a1dc3a73abdb0e2c750c33 Mon Sep 17 00:00:00 2001 From: mmetc <92726601+mmetc@users.noreply.github.com> Date: Wed, 20 Mar 2024 15:46:14 +0100 Subject: [PATCH] hub update: reload crowdsec if only data files have changed (#2912) --- pkg/cwhub/dataset.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/cwhub/dataset.go b/pkg/cwhub/dataset.go index 4612f3576..97fd9c5a0 100644 --- a/pkg/cwhub/dataset.go +++ b/pkg/cwhub/dataset.go @@ -32,6 +32,9 @@ func downloadFile(url string, destPath string) error { return fmt.Errorf("bad http code %d for %s", resp.StatusCode, url) } + // Download to a temporary location to avoid corrupting files + // that are currently in use or memory mapped. + tmpFile, err := os.CreateTemp(filepath.Dir(destPath), filepath.Base(destPath)+".*.tmp") if err != nil { return err @@ -57,6 +60,11 @@ func downloadFile(url string, destPath string) error { return err } + // a check on stdout is used while scripting to know if the hub has been upgraded + // and a configuration reload is required + // TODO: use a better way to communicate this + fmt.Printf("updated %s\n", filepath.Base(destPath)) + if err = os.Rename(tmpFileName, destPath); err != nil { return err }