double check if we actually try to open a dir

This commit is contained in:
gempir 2019-08-18 11:08:27 +02:00
parent 67a874606e
commit 13fc592d0a

View file

@ -1,13 +1,12 @@
package archiver package archiver
import ( import (
log "github.com/sirupsen/logrus"
"io/ioutil" "io/ioutil"
"os" "os"
"strconv" "strconv"
"strings" "strings"
"time" "time"
log "github.com/sirupsen/logrus"
) )
func (a *Archiver) scanLogPath() { func (a *Archiver) scanLogPath() {
@ -26,61 +25,66 @@ func (a *Archiver) scanLogPath() {
yearFiles = a.filterFiles(yearFiles) yearFiles = a.filterFiles(yearFiles)
for _, year := range yearFiles { for _, year := range yearFiles {
monthFiles, err := ioutil.ReadDir(a.logPath + "/" + channelId.Name() + "/" + year.Name()) if year.IsDir() {
if err != nil { monthFiles, err := ioutil.ReadDir(a.logPath + "/" + channelId.Name() + "/" + year.Name())
log.Error(err)
}
monthFiles = a.filterFiles(monthFiles)
for _, month := range monthFiles {
dayFiles, err := ioutil.ReadDir(a.logPath + "/" + channelId.Name() + "/" + year.Name() + "/" + month.Name())
if err != nil { if err != nil {
log.Error(err) log.Error(err)
} }
dayFiles = a.filterFiles(dayFiles) monthFiles = a.filterFiles(monthFiles)
for _, dayOrUserId := range dayFiles { for _, month := range monthFiles {
if dayOrUserId.IsDir() { if month.IsDir() {
channelLogFiles, err := ioutil.ReadDir(a.logPath + "/" + channelId.Name() + "/" + year.Name() + "/" + month.Name() + "/" + dayOrUserId.Name()) dayFiles, err := ioutil.ReadDir(a.logPath + "/" + channelId.Name() + "/" + year.Name() + "/" + month.Name())
if err != nil { if err != nil {
log.Error(err) log.Error(err)
} }
channelLogFiles = a.filterFiles(channelLogFiles) dayFiles = a.filterFiles(dayFiles)
for _, channelLogFile := range channelLogFiles { for _, dayOrUserId := range dayFiles {
if strings.HasSuffix(channelLogFile.Name(), ".txt") { if dayOrUserId.IsDir() {
dayInt, err := strconv.Atoi(dayOrUserId.Name()) channelLogFiles, err := ioutil.ReadDir(a.logPath + "/" + channelId.Name() + "/" + year.Name() + "/" + month.Name() + "/" + dayOrUserId.Name())
if err != nil { if err != nil {
log.Errorf("Failure converting day to int in scanner %s", err.Error()) log.Error(err)
}
channelLogFiles = a.filterFiles(channelLogFiles)
for _, channelLogFile := range channelLogFiles {
if strings.HasSuffix(channelLogFile.Name(), ".txt") {
dayInt, err := strconv.Atoi(dayOrUserId.Name())
if err != nil {
log.Errorf("Failure converting day to int in scanner %s", err.Error())
continue
}
if dayInt == int(time.Now().Day()) {
continue
}
a.workQueue <- a.logPath + "/" + channelId.Name() + "/" + year.Name() + "/" + month.Name() + "/" + dayOrUserId.Name() + "/" + channelLogFile.Name()
}
}
} else if strings.HasSuffix(dayOrUserId.Name(), ".txt") {
monthInt, err := strconv.Atoi(month.Name())
if err != nil {
log.Errorf("Failure converting month to int in scanner %s", err.Error())
continue continue
} }
if dayInt == int(time.Now().Day()) { if monthInt == int(time.Now().Month()) {
continue continue
} }
a.workQueue <- a.logPath + "/" + channelId.Name() + "/" + year.Name() + "/" + month.Name() + "/" + dayOrUserId.Name() + "/" + channelLogFile.Name() a.workQueue <- a.logPath + "/" + channelId.Name() + "/" + year.Name() + "/" + month.Name() + "/" + dayOrUserId.Name()
} }
} }
} else if strings.HasSuffix(dayOrUserId.Name(), ".txt") {
monthInt, err := strconv.Atoi(month.Name())
if err != nil {
log.Errorf("Failure converting month to int in scanner %s", err.Error())
continue
}
if monthInt == int(time.Now().Month()) {
continue
}
a.workQueue <- a.logPath + "/" + channelId.Name() + "/" + year.Name() + "/" + month.Name() + "/" + dayOrUserId.Name()
} }
} }
} }
} }
} }
} }