Skip to content

Commit

Permalink
Revert "[chore][fileconsumer] Cleanup file handle when closed by read…
Browse files Browse the repository at this point in the history
…er" (#26021)

Reverts #25912

This change appears to have caused special behaviors on windows.
  • Loading branch information
djaglowski authored Aug 21, 2023
1 parent fb7b990 commit c0040c0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 14 deletions.
5 changes: 4 additions & 1 deletion pkg/stanza/fileconsumer/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ func (m *Manager) consume(ctx context.Context, paths []string) {
r.ReadToEnd(ctx)
// Delete a file if deleteAfterRead is enabled and we reached the end of the file
if m.deleteAfterRead && r.eof {
r.Delete()
r.Close()
if err := os.Remove(r.file.Name()); err != nil {
m.Errorf("could not delete %s", r.file.Name())
}
}
}(r)
}
Expand Down
13 changes: 0 additions & 13 deletions pkg/stanza/fileconsumer/reader.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,25 +124,12 @@ func (r *reader) finalizeHeader() {
r.HeaderFinalized = true
}

// Delete will close and delete the file
func (r *reader) Delete() {
if r.file == nil {
return
}
f := r.file
r.Close()
if err := os.Remove(f.Name()); err != nil {
r.Errorf("could not delete %s", f.Name())
}
}

// Close will close the file
func (r *reader) Close() {
if r.file != nil {
if err := r.file.Close(); err != nil {
r.Debugw("Problem closing reader", zap.Error(err))
}
r.file = nil
}

if r.headerReader != nil {
Expand Down

0 comments on commit c0040c0

Please sign in to comment.