@@ -5,52 +5,38 @@ import (
55 "os"
66 "path/filepath"
77
8- log "github.com/sirupsen/logrus"
98 "gopkg.in/yaml.v3"
109
1110 leaky "github.com/crowdsecurity/crowdsec/pkg/leakybucket"
1211 "github.com/crowdsecurity/crowdsec/pkg/parser"
1312)
1413
15- func dumpAllStates () error {
16- log .Debugf ("Dumping parser+bucket states to %s" , parser .DumpFolder )
14+ func dumpAllStates (dir string ) error {
15+ err := os .MkdirAll (dir , 0o755 )
16+ if err != nil {
17+ return err
18+ }
1719
18- if err := dumpState (
19- filepath .Join (parser .DumpFolder , "parser-dump.yaml" ),
20- parser .StageParseCache ,
21- ); err != nil {
22- return fmt .Errorf ("while dumping parser state: %w" , err )
20+ if err := dumpState (dir , "parser-dump.yaml" , parser .StageParseCache ); err != nil {
21+ return fmt .Errorf ("dumping parser state: %w" , err )
2322 }
2423
25- if err := dumpState (
26- filepath .Join (parser .DumpFolder , "bucket-dump.yaml" ),
27- bucketOverflows ,
28- ); err != nil {
29- return fmt .Errorf ("while dumping bucket overflow state: %w" , err )
24+ if err := dumpState (dir , "bucket-dump.yaml" , bucketOverflows ); err != nil {
25+ return fmt .Errorf ("dumping bucket overflow state: %w" , err )
3026 }
3127
32- if err := dumpState (
33- filepath .Join (parser .DumpFolder , "bucketpour-dump.yaml" ),
34- leaky .BucketPourCache ,
35- ); err != nil {
36- return fmt .Errorf ("while dumping bucket pour state: %w" , err )
28+ if err := dumpState (dir , "bucketpour-dump.yaml" , leaky .BucketPourCache ); err != nil {
29+ return fmt .Errorf ("dumping bucket pour state: %w" , err )
3730 }
3831
3932 return nil
4033}
4134
42- func dumpState (destPath string , obj any ) error {
43- dir := filepath .Dir (destPath )
44-
45- err := os .MkdirAll (dir , 0o755 )
46- if err != nil {
47- return err
48- }
49-
35+ func dumpState (dir , name string , obj any ) error {
5036 out , err := yaml .Marshal (obj )
5137 if err != nil {
5238 return err
5339 }
5440
55- return os .WriteFile (destPath , out , 0o666 )
41+ return os .WriteFile (filepath . Join ( dir , name ) , out , 0o666 )
5642}
0 commit comments