Skip to content

Commit

Permalink
address pr comments
Browse files Browse the repository at this point in the history
  • Loading branch information
efd6 committed Sep 28, 2023
1 parent e0327b6 commit 5d57495
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
2 changes: 1 addition & 1 deletion libbeat/processors/cache/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ type memConfig struct {

type fileConfig struct {
ID string `config:"id"`
WriteOutEvery time.Duration `config:"write_frequency"`
WriteOutEvery time.Duration `config:"write_interval"`
}

func (cfg *storeConfig) Validate() error {
Expand Down
2 changes: 1 addition & 1 deletion libbeat/processors/cache/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ put:
backend:
file:
id: aidmaster
write_frequency: 15m
write_interval: 15m
put:
ttl: 168h
key_field: crowdstrike.aid
Expand Down
16 changes: 13 additions & 3 deletions libbeat/processors/cache/file_store.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,12 @@ func (c *fileStore) readState() {
err = dec.Decode(&e)
if err != nil {
if err != io.EOF {

Check failure on line 171 in libbeat/processors/cache/file_store.go

View workflow job for this annotation

GitHub Actions / lint (linux)

comparing with != will fail on wrapped errors. Use errors.Is to check for a specific error (errorlint)
c.log.Errorw("failed to read state element", "error", err)
switch err := err.(type) {

Check failure on line 172 in libbeat/processors/cache/file_store.go

View workflow job for this annotation

GitHub Actions / lint (linux)

type switch on error will fail on wrapped errors. Use errors.As to check for specific errors (errorlint)
case *json.SyntaxError:
c.log.Errorw("failed to read state element", "error", err, "path", c.path, "offset", err.Offset)
default:
c.log.Errorw("failed to read state element", "error", err, "path", c.path)
}
}
break
}
Expand Down Expand Up @@ -219,19 +224,24 @@ func (c *fileStore) writeState(final bool) {
}
return
}
f, err := os.CreateTemp("", "")
f, err := os.CreateTemp(filepath.Dir(c.path), "")
if err != nil {
c.log.Errorw("failed to open file to write state", "error", err)
return
}
// We are writing into tmp, so make sure we are private.
// Try to make sure we are private.
err = os.Chmod(f.Name(), 0o600)
if err != nil {
c.log.Errorw("failed to set state file mode", "error", err)
return
}
tmp := f.Name()
defer func() {
err = f.Sync()
if err != nil {
c.log.Errorw("failed to sync file after writing state", "error", err)
return
}
err = f.Close()
if err != nil {
c.log.Errorw("failed to close file after writing state", "error", err)
Expand Down

0 comments on commit 5d57495

Please sign in to comment.