mirror of
https://github.com/tickstep/aliyunpan.git
synced 2025-01-23 14:32:14 +08:00
refactor upload exclude file method
This commit is contained in:
parent
4a4796218e
commit
15084b3ac2
@ -23,7 +23,6 @@ import (
|
||||
"os"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
@ -338,7 +337,7 @@ func RunUpload(localPaths []string, savePath string, opt *UploadOptions) {
|
||||
localPathDir := filepath.Dir(curPath)
|
||||
|
||||
// 是否排除上传
|
||||
if isExcludeFile(curPath, opt) {
|
||||
if isExcludeFile(curPath, &opt.ExcludeNames) {
|
||||
fmt.Printf("排除文件: %s\n", curPath)
|
||||
continue
|
||||
}
|
||||
@ -360,7 +359,7 @@ func RunUpload(localPaths []string, savePath string, opt *UploadOptions) {
|
||||
}
|
||||
|
||||
// 是否排除上传
|
||||
if isExcludeFile(file.LogicPath, opt) {
|
||||
if isExcludeFile(file.LogicPath, &opt.ExcludeNames) {
|
||||
fmt.Printf("排除文件: %s\n", file.LogicPath)
|
||||
return filepath.SkipDir
|
||||
}
|
||||
@ -474,22 +473,6 @@ func RunUpload(localPaths []string, savePath string, opt *UploadOptions) {
|
||||
activeUser.DeleteCache(GetAllPathFolderByPath(savePath))
|
||||
}
|
||||
|
||||
// 是否是排除上传的文件
|
||||
func isExcludeFile(filePath string, opt *UploadOptions) bool {
|
||||
if opt == nil || len(opt.ExcludeNames) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, pattern := range opt.ExcludeNames {
|
||||
fileName := path.Base(strings.ReplaceAll(filePath, "\\", "/"))
|
||||
m, _ := regexp.MatchString(pattern, fileName)
|
||||
if m {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// RunRapidUpload 秒传
|
||||
func RunRapidUpload(driveId string, isOverwrite bool, fileMetaList []string, savePanPath string) {
|
||||
activeUser := GetActiveUser()
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
"net/url"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
@ -165,3 +166,19 @@ func isIncludeFile(pattern string, fileName string) bool {
|
||||
func isMatchWildcardPattern(name string) bool {
|
||||
return strings.ContainsAny(name, "*") || strings.ContainsAny(name, "?") || strings.ContainsAny(name, "[")
|
||||
}
|
||||
|
||||
// 是否是指定排除的文件
|
||||
func isExcludeFile(filePath string, excludeNames *[]string) bool {
|
||||
if excludeNames == nil || len(*excludeNames) == 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
for _, pattern := range *excludeNames {
|
||||
fileName := path.Base(strings.ReplaceAll(filePath, "\\", "/"))
|
||||
m, _ := regexp.MatchString(pattern, fileName)
|
||||
if m {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user