pick up existing files on start
This commit is contained in:
parent
6570a2b3f8
commit
d181172c30
23
cmd/mower.go
23
cmd/mower.go
@ -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)
|
||||
if err != nil {
|
||||
@ -258,3 +263,19 @@ func parseLogName(name string) (m logMeta, ok bool) {
|
||||
|
||||
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
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ func (s *submitter) shipFileRoutine(ctx context.Context, name string, deleteOk f
|
||||
|
||||
fi, err := os.Stat(name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("getting original file size")
|
||||
return fmt.Errorf("getting original file size: %w", err)
|
||||
}
|
||||
startSize := fi.Size()
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user