mirror of
https://github.com/ProtonMail/proton-bridge.git
synced 2025-12-15 14:56:42 +00:00
GODT-2149: Sort logs by timestamp when clearing
This commit is contained in:
@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user