瀏覽代碼

hub update: reload crowdsec if only data files have changed (#2912)

mmetc 1 年之前
父節點
當前提交
7779c7ff0c
共有 1 個文件被更改,包括 8 次插入0 次删除
  1. 8 0
      pkg/cwhub/dataset.go

+ 8 - 0
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)
 		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")
 	tmpFile, err := os.CreateTemp(filepath.Dir(destPath), filepath.Base(destPath)+".*.tmp")
 	if err != nil {
 	if err != nil {
 		return err
 		return err
@@ -57,6 +60,11 @@ func downloadFile(url string, destPath string) error {
 		return err
 		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 {
 	if err = os.Rename(tmpFileName, destPath); err != nil {
 		return err
 		return err
 	}
 	}