// GetState returns current state of harvester func (h *Harvester) GetState() *input.FileState { state := input.FileState{ Source: h.Path, Offset: h.GetOffset(), FileStateOS: input.GetOSFileState(&h.Stat.Fileinfo), } return &state }
// getPreviousFile checks in the registrar if there is the newFile already exist with a different name // In case an old file is found, the path to the file is returned, if not, an error is returned func (r *Registrar) getPreviousFile(newFilePath string, newFileInfo os.FileInfo) (string, error) { newState := input.GetOSFileState(newFileInfo) for oldFilePath, oldState := range r.getState() { // Compare states if newState.IsSame(oldState.FileStateOS) { logp.Info("Old file with new name found: %s -> %s", oldFilePath, newFilePath) return oldFilePath, nil } } return "", fmt.Errorf("No previous file found") }
// getPreviousFile checks in the registrar if there is the newFile already exist with a different name // In case an old file is found, the path to the file is returned, if not, an error is returned func (r *Registrar) getPreviousFile(newFilePath string, newFileInfo os.FileInfo) (string, error) { newState := input.GetOSFileState(&newFileInfo) for oldFilePath, oldState := range r.State { // Skipping when path the same if oldFilePath == newFilePath { continue } // Compare states if newState.IsSame(oldState.FileStateOS) { logp.Info("Old file with new name found: %s is no %s", oldFilePath, newFilePath) return oldFilePath, nil } } return "", fmt.Errorf("No previous file found") }
// createEvent creates and empty event. // By default the offset is set to 0, means no bytes read. This can be used to report the status // of a harvester func (h *Harvester) createEvent() *input.FileEvent { event := &input.FileEvent{ EventMetadata: h.Config.EventMetadata, Source: h.Path, InputType: h.Config.InputType, DocumentType: h.Config.DocumentType, Offset: h.getOffset(), Bytes: 0, Fileinfo: h.Stat.Fileinfo, JSONConfig: h.Config.JSON, } if h.Config.InputType != config.StdinInputType { event.FileState = input.FileState{ Source: h.Path, Offset: h.getOffset(), FileStateOS: input.GetOSFileState(h.Stat.Fileinfo), } } return event }
// refreshState refreshes the values in State with the values from the harvester itself func (h *Harvester) refreshState() { h.State.Source = h.Path h.State.Offset = h.getOffset() h.State.FileStateOS = input.GetOSFileState(h.State.Fileinfo) }