mirror of
https://github.com/tickstep/aliyunpan.git
synced 2025-01-23 22:42:15 +08:00
refactor upload exclude file method
This commit is contained in:
parent
4a4796218e
commit
15084b3ac2
@ -23,7 +23,6 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"regexp"
|
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@ -338,7 +337,7 @@ func RunUpload(localPaths []string, savePath string, opt *UploadOptions) {
|
|||||||
localPathDir := filepath.Dir(curPath)
|
localPathDir := filepath.Dir(curPath)
|
||||||
|
|
||||||
// 是否排除上传
|
// 是否排除上传
|
||||||
if isExcludeFile(curPath, opt) {
|
if isExcludeFile(curPath, &opt.ExcludeNames) {
|
||||||
fmt.Printf("排除文件: %s\n", curPath)
|
fmt.Printf("排除文件: %s\n", curPath)
|
||||||
continue
|
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)
|
fmt.Printf("排除文件: %s\n", file.LogicPath)
|
||||||
return filepath.SkipDir
|
return filepath.SkipDir
|
||||||
}
|
}
|
||||||
@ -474,22 +473,6 @@ func RunUpload(localPaths []string, savePath string, opt *UploadOptions) {
|
|||||||
activeUser.DeleteCache(GetAllPathFolderByPath(savePath))
|
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 秒传
|
// RunRapidUpload 秒传
|
||||||
func RunRapidUpload(driveId string, isOverwrite bool, fileMetaList []string, savePanPath string) {
|
func RunRapidUpload(driveId string, isOverwrite bool, fileMetaList []string, savePanPath string) {
|
||||||
activeUser := GetActiveUser()
|
activeUser := GetActiveUser()
|
||||||
|
@ -22,6 +22,7 @@ import (
|
|||||||
"net/url"
|
"net/url"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
@ -165,3 +166,19 @@ func isIncludeFile(pattern string, fileName string) bool {
|
|||||||
func isMatchWildcardPattern(name string) bool {
|
func isMatchWildcardPattern(name string) bool {
|
||||||
return strings.ContainsAny(name, "*") || strings.ContainsAny(name, "?") || strings.ContainsAny(name, "[")
|
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