GODT-2149: Sort logs by timestamp when clearing

This commit is contained in:
James Houlahan
2022-11-23 15:10:08 +01:00
parent 578a12529c
commit c3484dc062
3 changed files with 62 additions and 50 deletions

View File

@ -24,6 +24,7 @@ import (
"os"
"path/filepath"
"regexp"
"strconv"
"time"
"github.com/ProtonMail/proton-bridge/v3/internal/constants"
@ -141,6 +142,17 @@ func getLogName(version, revision string) string {
return fmt.Sprintf("v%v_%v_%v.log", version, revision, time.Now().Unix())
}
func getLogTime(name string) int {
re := regexp.MustCompile(`^v.*_.*_(?P<timestamp>\d+).log$`)
timestamp, err := strconv.Atoi(re.FindStringSubmatch(name)[re.SubexpIndex("timestamp")])
if err != nil {
return 0
}
return timestamp
}
func MatchLogName(name string) bool {
return regexp.MustCompile(`^v.*\.log$`).MatchString(name)
}