(file string, out chan pipeline.Event, seekEnd bool, t *tomb.Tomb)
| 189 | } |
| 190 | |
| 191 | func (s *Source) setupTailForFile(file string, out chan pipeline.Event, seekEnd bool, t *tomb.Tomb) error { |
| 192 | logger := s.logger.WithField("file", file) |
| 193 | |
| 194 | if s.isExcluded(file) { |
| 195 | return nil |
| 196 | } |
| 197 | |
| 198 | // Check if we're already tailing |
| 199 | s.tailMapMutex.RLock() |
| 200 | |
| 201 | if s.tails[file] { |
| 202 | s.tailMapMutex.RUnlock() |
| 203 | logger.Debugf("Already tailing file %s, not creating a new tail", file) |
| 204 | |
| 205 | return nil |
| 206 | } |
| 207 | |
| 208 | s.tailMapMutex.RUnlock() |
| 209 | |
| 210 | // Validate file |
| 211 | fd, err := os.Open(file) |
| 212 | if err != nil { |
| 213 | return fmt.Errorf("unable to read %s : %s", file, err) |
| 214 | } |
| 215 | |
| 216 | if err = fd.Close(); err != nil { |
| 217 | return fmt.Errorf("unable to close %s : %s", file, err) |
| 218 | } |
| 219 | |
| 220 | fi, err := os.Stat(file) |
| 221 | if err != nil { |
| 222 | return fmt.Errorf("could not stat file %s : %w", file, err) |
| 223 | } |
| 224 | |
| 225 | if fi.IsDir() { |
| 226 | logger.Warnf("%s is a directory, ignoring it.", file) |
| 227 | return nil |
| 228 | } |
| 229 | |
| 230 | // Determine polling mode |
| 231 | pollFile := false |
| 232 | if s.config.PollWithoutInotify != nil { |
| 233 | pollFile = *s.config.PollWithoutInotify |
| 234 | } else { |
| 235 | networkFS, fsType, err := fsutil.IsNetworkFS(file) |
| 236 | if err != nil { |
| 237 | logger.Warningf("Could not get fs type for %s : %s", file, err) |
| 238 | } |
| 239 | |
| 240 | logger.Debugf("fs for %s is network: %t (%s)", file, networkFS, fsType) |
| 241 | |
| 242 | if networkFS { |
| 243 | logger.Warnf("Disabling inotify polling on %s as it is on a network share. You can manually set poll_without_inotify to true to make this message disappear, or to false to enforce inotify poll", file) |
| 244 | |
| 245 | pollFile = true |
| 246 | } |
| 247 | } |
| 248 |
no test coverage detected