summaryrefslogtreecommitdiff
path: root/internal/io/fs/filereader.go
blob: c89f346aa60e1dfbdd125804ce51ed21e06db15b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Package fs provides file system operations and processors for DTail server-side
// log file handling. This package implements various file processing strategies
// including tailing, reading, grepping, and MapReduce operations with efficient
// streaming and resource management.
//
// Key components:
// - FileReader interface for abstracted file operations
// - Processors for different operation types (tail, cat, grep, mapr)
// - Chunked reading for efficient large file processing
// - Permission checking with Linux ACL support (optional)
// - Statistics tracking for file operations
//
// The package supports both one-time operations (cat, grep, mapr) and continuous
// monitoring (tail) with proper resource cleanup and error handling. All processors
// implement streaming output to minimize memory usage for large files.
package fs

import (
	"context"

	"github.com/mimecast/dtail/internal/io/line"
	"github.com/mimecast/dtail/internal/lcontext"
	"github.com/mimecast/dtail/internal/regex"
)

// FileReader defines the interface for all file processing operations on the
// DTail server. This interface abstracts different file processing strategies
// (tail, cat, grep, mapr) providing a uniform way to handle various log file
// operations with context management and streaming output.
type FileReader interface {
	// Start begins the file processing operation, streaming processed lines
	// to the output channel. The operation respects context cancellation
	// and applies regex filtering as specified.
	//
	// Parameters:
	//   ctx: Context for cancellation and timeout control
	//   ltx: Line context for before/after context lines and match limits
	//   lines: Output channel for processed log lines
	//   re: Compiled regex for line filtering (may be no-op for some operations)
	//
	// Returns:
	//   error: Any error encountered during file processing
	Start(ctx context.Context, ltx lcontext.LContext, lines chan<- *line.Line,
		re regex.Regex) error
	
	// FilePath returns the absolute path of the file being processed.
	// This is used for logging, statistics, and client identification.
	FilePath() string
	
	// Retry indicates whether this file operation should be retried
	// if it fails. Typically true for tail operations (long-running)
	// and false for one-time operations (cat, grep, mapr).
	Retry() bool
}