Browse Source

修复单次扫描日志的删除bug

Signed-off-by: allan716 <[email protected]>
allan716 3 years ago
parent
commit
a4f41b45c9

+ 2 - 1
internal/logic/task_queue/task_queue.go

@@ -7,6 +7,7 @@ import (
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/global_value"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/global_value"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/my_util"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/settings"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/settings"
+	"github.com/allanpk716/ChineseSubFinder/internal/types/common"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/task_queue"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/task_queue"
 	taskQueue2 "github.com/allanpk716/ChineseSubFinder/internal/types/task_queue"
 	taskQueue2 "github.com/allanpk716/ChineseSubFinder/internal/types/task_queue"
 	"github.com/dgraph-io/badger/v3"
 	"github.com/dgraph-io/badger/v3"
@@ -331,7 +332,7 @@ func (t *TaskQueue) del(jobId string) (bool, error) {
 	}
 	}
 	// 删除任务的时候也需要删除对应的日志
 	// 删除任务的时候也需要删除对应的日志
 	pathRoot := filepath.Join(global_value.ConfigRootDirFPath(), "Logs")
 	pathRoot := filepath.Join(global_value.ConfigRootDirFPath(), "Logs")
-	fileFPath := filepath.Join(pathRoot, jobId)
+	fileFPath := filepath.Join(pathRoot, common.OnceLogPrefix+jobId+".log")
 	if my_util.IsFile(fileFPath) == true {
 	if my_util.IsFile(fileFPath) == true {
 		err = os.Remove(fileFPath)
 		err = os.Remove(fileFPath)
 		if err != nil {
 		if err != nil {

+ 6 - 5
internal/pkg/log_helper/log_hub.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"fmt"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/global_value"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/global_value"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/regex_things"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/regex_things"
+	"github.com/allanpk716/ChineseSubFinder/internal/types/common"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/log_hub"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/log_hub"
 	"github.com/huandu/go-clone"
 	"github.com/huandu/go-clone"
 	"github.com/sirupsen/logrus"
 	"github.com/sirupsen/logrus"
@@ -173,7 +174,7 @@ func newOnceLogger(logFileName string) *logrus.Logger {
 		LogFormat:       "[%lvl%]: %time% - %msg%\n",
 		LogFormat:       "[%lvl%]: %time% - %msg%\n",
 	}
 	}
 	pathRoot := filepath.Join(global_value.ConfigRootDirFPath(), "Logs")
 	pathRoot := filepath.Join(global_value.ConfigRootDirFPath(), "Logs")
-	fileName := fmt.Sprintf(onceLogPrefix+"%v.log", logFileName)
+	fileName := fmt.Sprintf(common.OnceLogPrefix+"%v.log", logFileName)
 	fileAbsPath := filepath.Join(pathRoot, fileName)
 	fileAbsPath := filepath.Join(pathRoot, fileName)
 
 
 	// 注意这个函数的调用时机
 	// 注意这个函数的调用时机
@@ -206,7 +207,7 @@ func cleanAndLoadOnceLogs() {
 	pathRoot := filepath.Join(global_value.ConfigRootDirFPath(), "Logs")
 	pathRoot := filepath.Join(global_value.ConfigRootDirFPath(), "Logs")
 	// 扫描当前日志存储目录下有多少个符合要求的 Once- 日志
 	// 扫描当前日志存储目录下有多少个符合要求的 Once- 日志
 	// 确保有且仅有最近的 20 次扫描日志记录存在即可
 	// 确保有且仅有最近的 20 次扫描日志记录存在即可
-	matches, err := filepath.Glob(filepath.Join(pathRoot, onceLogPrefix+"*.log"))
+	matches, err := filepath.Glob(filepath.Join(pathRoot, common.OnceLogPrefix+"*.log"))
 	if err != nil {
 	if err != nil {
 		panic(err)
 		panic(err)
 	}
 	}
@@ -223,7 +224,7 @@ func cleanAndLoadOnceLogs() {
 			_ = os.Remove(matches[i])
 			_ = os.Remove(matches[i])
 		}
 		}
 		// 将有存在价值的“单次”日志缓存到内存中,供 Web API 查询
 		// 将有存在价值的“单次”日志缓存到内存中,供 Web API 查询
-		matches, err = filepath.Glob(filepath.Join(pathRoot, onceLogPrefix+"*.log"))
+		matches, err = filepath.Glob(filepath.Join(pathRoot, common.OnceLogPrefix+"*.log"))
 		if err != nil {
 		if err != nil {
 			panic(err)
 			panic(err)
 		}
 		}
@@ -275,8 +276,8 @@ var (
 )
 )
 
 
 const (
 const (
-	onceLogMaxCount   = 10000
-	onceLogPrefix     = "Once-"
+	onceLogMaxCount = 10000
+
 	OnceSubsScanStart = "OneTimeSubtitleScanStart"
 	OnceSubsScanStart = "OneTimeSubtitleScanStart"
 	OnceSubsScanEnd   = "OneTimeSubtitleScanEnd"
 	OnceSubsScanEnd   = "OneTimeSubtitleScanEnd"
 )
 )

+ 2 - 0
internal/types/common/constvalue.go

@@ -46,3 +46,5 @@ const (
 const QueueName = "Queue"
 const QueueName = "Queue"
 
 
 const StaticFileName00 = "c31ViaG5Q.txt"
 const StaticFileName00 = "c31ViaG5Q.txt"
+
+const OnceLogPrefix = "Once-"