diff --git a/eliofile/eliofile.go b/eliofile/eliofile.go index a5b8054..cd51155 100644 --- a/eliofile/eliofile.go +++ b/eliofile/eliofile.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "strings" + "sync" "time" "gittea.marcokittel.de/elio/eliotools/tools" @@ -21,11 +22,14 @@ type ElioDateiFoo struct { process ElioHandleFunc lookUpDir string processedDir string + mu sync.RWMutex + haveDone map[string]time.Time } func NewElioDateiFoo(lookUpDir string, process ElioHandleFunc) *ElioDateiFoo { df := ElioDateiFoo{lookUpDir: lookUpDir, - process: process, + process: process, + haveDone: make(map[string]time.Time), } return &df } @@ -65,6 +69,15 @@ func (f *ElioDateiFoo) ScanCsv() { } } for _, v := range filemap { - f.process(v.filename) + f.mu.RLock() + _, ok := f.haveDone[v.filename] + f.mu.RUnlock() + if ok { + break + } + f.mu.Lock() + f.haveDone[v.filename] = time.Now() + f.mu.Unlock() + go f.process(v.filename) } }