pick up existing files on start

This commit is contained in:
rasmus 2022-11-06 04:04:32 +02:00
parent 6570a2b3f8
commit d181172c30
2 changed files with 23 additions and 2 deletions

View File

@ -172,7 +172,12 @@ var App = &cli.App{
} }
}() }()
// TODO: simulate create events files for current files // simulate create events to pick up files already created
err = simulateInitialCreate(logDir, watcher.Events)
if err != nil {
promErrWatching.Add(1)
l.Fatal("listing initial log directory", zap.String("name", logDir), zap.Error(err))
}
err = watcher.Add(logDir) err = watcher.Add(logDir)
if err != nil { if err != nil {
@ -258,3 +263,19 @@ func parseLogName(name string) (m logMeta, ok bool) {
return m, true return m, true
} }
func simulateInitialCreate(dirName string, eventChan chan<- fsnotify.Event) error {
dir, err := os.ReadDir(dirName)
if err != nil {
return err
}
for _, file := range dir {
eventChan <- fsnotify.Event{
Name: filepath.Join(dirName, file.Name()),
Op: fsnotify.Create,
}
}
return nil
}

View File

@ -113,7 +113,7 @@ func (s *submitter) shipFileRoutine(ctx context.Context, name string, deleteOk f
fi, err := os.Stat(name) fi, err := os.Stat(name)
if err != nil { if err != nil {
return fmt.Errorf("getting original file size") return fmt.Errorf("getting original file size: %w", err)
} }
startSize := fi.Size() startSize := fi.Size()