Преглед изворни кода

修复 gorm first 查询没有结果也会返回 Error 的问题,fix #180 #181

Signed-off-by: 716 <[email protected]>
716 пре 3 година
родитељ
комит
6738d1698b

+ 2 - 0
.gitignore

@@ -76,3 +76,5 @@ TestData/
 /*.iml
 /ChineseSubFinder-Cache.db
 /cache
+/internal/pkg/hot_fix/ChineseSubFinder-Cache.db
+/internal/pkg/sub_formatter/ChineseSubFinder-Cache.db

+ 4 - 5
internal/pkg/folder_helper/folder_test.go

@@ -2,13 +2,12 @@ package folder_helper
 
 import (
 	"testing"
-	"time"
 )
 
 func TestClearIdleSubFixCacheFolder(t *testing.T) {
 
-	err := ClearIdleSubFixCacheFolder("W:\\CSF-SubFixCache", 24*time.Hour)
-	if err != nil {
-		t.Fatal(err)
-	}
+	//err := ClearIdleSubFixCacheFolder("W:\\CSF-SubFixCache", 24*time.Hour)
+	//if err != nil {
+	//	t.Fatal(err)
+	//}
 }

+ 2 - 2
internal/pkg/hot_fix/hot_fix_001_test.go

@@ -8,7 +8,7 @@ import (
 )
 
 func TestHotFix001_GetKey(t *testing.T) {
-	hf001 := NewHotFix001("", "")
+	hf001 := NewHotFix001([]string{""}, []string{""})
 	if hf001.GetKey() != "001" {
 		t.Fatal("GetKey() != 001")
 	}
@@ -23,7 +23,7 @@ func TestHotFix001_Process(t *testing.T) {
 	testMovieDir := filepath.Join(testDataPath, movieDir)
 	testSeriesDir := filepath.Join(testDataPath, seriesDir)
 	// 开始修复
-	hf001 := NewHotFix001(testMovieDir, testSeriesDir)
+	hf001 := NewHotFix001([]string{testMovieDir}, []string{testSeriesDir})
 	outData, err := hf001.Process()
 	outStruct := outData.(OutStruct001)
 	if err != nil {

+ 4 - 1
internal/pkg/sub_formatter/sub_format_changer.go

@@ -16,6 +16,7 @@ import (
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_formatter/normal"
 	"github.com/allanpk716/ChineseSubFinder/internal/pkg/sub_helper"
 	"github.com/allanpk716/ChineseSubFinder/internal/types/subparser"
+	"gorm.io/gorm"
 	"os"
 	"path/filepath"
 	"strings"
@@ -246,7 +247,9 @@ func SubFormatChangerProcess(movieRootDirs []string, seriesRootDirs []string, no
 		return RenameResults{}, errors.New(fmt.Sprintf("SubFormatChangerProcess dao.GetDb().First return nil"))
 	}
 	if re.Error != nil {
-		return RenameResults{}, errors.New(fmt.Sprintf("SubFormatChangerProcess dao.GetDb().First, %v", re.Error))
+		if re.Error != gorm.ErrRecordNotFound {
+			return RenameResults{}, errors.New(fmt.Sprintf("SubFormatChangerProcess dao.GetDb().First, %v", re.Error))
+		}
 	}
 	subFormatChanger := NewSubFormatChanger(movieRootDirs, seriesRootDirs)
 	// 理论上有且仅有一条记录