Skip to content

Commit

Permalink
hub update: reload crowdsec if only data files have changed (#2912)
Browse files Browse the repository at this point in the history
  • Loading branch information
mmetc authored Mar 20, 2024
1 parent 75a50c0 commit 7779c7f
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/cwhub/dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
Expand Down

0 comments on commit 7779c7f

Please sign in to comment.