package executor import ( "fmt" schemepkg "git.buran.team/main/cep/scheme" fw "git.buran.team/main/fairwind" ) type CheckFile struct { global *Global ticket *Ticket id string container Container timeout int path string processors []Processor } func NewCheckFile(global *Global, ticket *Ticket, container Container, checkScheme schemepkg.Check) (*CheckFile, error) { processors := []Processor{} for _, processorScheme := range checkScheme.KindFile.Processors { processor, err := NewProcessor(processorScheme) if err != nil { return nil, fmt.Errorf("can't create result: %w", err) } processors = append(processors, processor) } return &CheckFile{ global: global, ticket: ticket, id: checkScheme.ID, container: container, timeout: checkScheme.Timeout, path: checkScheme.KindFile.Path, processors: processors, }, nil } func (this *CheckFile) ID() string { return this.id } func (this *CheckFile) Check() CheckResult { this.global.Log.Debug("beginning file check", fw.LogValue("uuid", this.ticket.UUID)) buffer, err := this.container.Read(this.timeout, this.path) if err != nil { this.global.Log.Debug("file check ended with error", fw.LogValue("uuid", this.ticket.UUID), fw.LogError(err)) return CheckResult{ Success: false, Data: nil, } } for _, processor := range this.processors { if !processor.Process(buffer) { this.global.Log.Debug("file check ended with error", fw.LogValue("uuid", this.ticket.UUID)) return CheckResult{ Success: false, Data: nil, } } } this.global.Log.Debug("file check ended successfully", fw.LogValue("uuid", this.ticket.UUID)) return CheckResult{ Success: true, Data: nil, } }