Просмотр исходного кода

修复软连接跳过的问题 fix #558

Signed-off-by: allan716 <[email protected]>
allan716 3 лет назад
Родитель
Сommit
bebb5b1369
4 измененных файлов с 27 добавлено и 12 удалено
  1. 18 3
      pkg/filter/filter.go
  2. 3 3
      pkg/search/search.go
  3. 5 5
      pkg/sub_helper/sub_helper.go
  4. 1 1
      pkg/sub_parser_hub/subParserHub.go

+ 18 - 3
pkg/filter/filter.go

@@ -8,7 +8,7 @@ import (
 	"github.com/sirupsen/logrus"
 )
 
-func SkipFileInfo(l *logrus.Logger, curFile os.DirEntry) bool {
+func SkipFileInfo(l *logrus.Logger, curFile os.DirEntry, fileFullPath string) bool {
 
 	if curFile.IsDir() == true {
 		// 排除缓存文件夹,见 #532
@@ -27,8 +27,23 @@ func SkipFileInfo(l *logrus.Logger, curFile os.DirEntry) bool {
 
 	// 软链接问题 #558
 	if fi.Size() < 1000 {
-		l.Debugln("curFile.Size() < 1000:", curFile.Name())
-		return true
+
+		fileInfo, err := os.Lstat(fileFullPath)
+		if err != nil {
+			l.Errorln("os.Lstat:", fileFullPath, err)
+			return true
+		}
+		if fileInfo.Mode()&os.ModeSymlink != 0 {
+			// 确认是软连接
+			l.Debugln("curFile is symlink,", fileFullPath)
+			//realPath, err := filepath.EvalSymlinks(fileFullPath)
+			//if err == nil {
+			//	fmt.Println("Path:", realPath)
+			//}
+		} else {
+			l.Debugln("curFile.Size() < 1000:", curFile.Name())
+			return true
+		}
 	}
 
 	if fi.Size() == 4096 && strings.HasPrefix(curFile.Name(), "._") == true {

+ 3 - 3
pkg/search/search.go

@@ -114,7 +114,7 @@ func MatchedVideoFile(l *logrus.Logger, dir string) ([]string, error) {
 					continue
 				}
 
-				if filter.SkipFileInfo(l, curFile) == true {
+				if filter.SkipFileInfo(l, curFile, fullPath) == true {
 					continue
 				}
 
@@ -147,7 +147,7 @@ func TVNfo(l *logrus.Logger, dir string) ([]string, error) {
 				continue
 			} else {
 
-				if filter.SkipFileInfo(l, curFile) == true {
+				if filter.SkipFileInfo(l, curFile, fullPath) == true {
 					continue
 				}
 				fileFullPathList = append(fileFullPathList, fullPath)
@@ -177,7 +177,7 @@ func SeriesAllEpsAndSubtitles(l *logrus.Logger, dir string) (*backend.SeasonInfo
 			return nil
 		}
 
-		if filter.SkipFileInfo(l, d) == true {
+		if filter.SkipFileInfo(l, d, path) == true {
 			return nil
 		}
 

+ 5 - 5
pkg/sub_helper/sub_helper.go

@@ -256,7 +256,7 @@ func SearchMatchedSubFileByDir(log *logrus.Logger, dir string) ([]string, error)
 			}
 		} else {
 			// 这里就是文件了
-			if filter.SkipFileInfo(log, curFile) == true {
+			if filter.SkipFileInfo(log, curFile, fullPath) == true {
 				continue
 			}
 
@@ -287,7 +287,8 @@ func SearchMatchedSubFileByOneVideo(l *logrus.Logger, oneVideoFullPath string) (
 			continue
 		}
 		// 这里就是文件了
-		if filter.SkipFileInfo(l, curFile) == true {
+		oldPath := dir + pathSep + curFile.Name()
+		if filter.SkipFileInfo(l, curFile, oldPath) == true {
 			continue
 		}
 
@@ -302,7 +303,6 @@ func SearchMatchedSubFileByOneVideo(l *logrus.Logger, oneVideoFullPath string) (
 			continue
 		}
 
-		oldPath := dir + pathSep + curFile.Name()
 		matchedSubs = append(matchedSubs, oldPath)
 	}
 
@@ -326,7 +326,8 @@ func SearchVideoMatchSubFileAndRemoveExtMark(l *logrus.Logger, oneVideoFullPath
 			continue
 		} else {
 			// 这里就是文件了
-			if filter.SkipFileInfo(l, curFile) == true {
+			oldPath := dir + pathSep + curFile.Name()
+			if filter.SkipFileInfo(l, curFile, oldPath) == true {
 				continue
 			}
 			// 判断的时候用小写的,后续重命名的时候用原有的名称
@@ -343,7 +344,6 @@ func SearchVideoMatchSubFileAndRemoveExtMark(l *logrus.Logger, oneVideoFullPath
 			if strings.Contains(nowFileName, subparser.Sub_Ext_Mark_Default+".") == true {
 				// 得包含 .default. 找个关键词
 				// 去除 .default.
-				oldPath := dir + pathSep + curFile.Name()
 				newPath := dir + pathSep + strings.ReplaceAll(curFile.Name(), subparser.Sub_Ext_Mark_Default+".", ".")
 				err = os.Rename(oldPath, newPath)
 				if err != nil {

+ 1 - 1
pkg/sub_parser_hub/subParserHub.go

@@ -201,7 +201,7 @@ func SearchMatchedSubFile(log *logrus.Logger, dir string) ([]string, error) {
 			} else {
 
 				// 跳过不符合的文件,比如 MAC OS 下可能有缓存文件,见 #138
-				if filter.SkipFileInfo(log, curFile) == true {
+				if filter.SkipFileInfo(log, curFile, fullPath) == true {
 					continue
 				}