mirror of
https://github.com/tickstep/aliyunpan.git
synced 2025-02-03 05:47:16 +08:00
add skip args
This commit is contained in:
parent
6a7da9f180
commit
7f5e19812e
@ -62,6 +62,7 @@ type (
|
|||||||
NoRapidUpload bool
|
NoRapidUpload bool
|
||||||
ShowProgress bool
|
ShowProgress bool
|
||||||
IsOverwrite bool // 覆盖已存在的文件,如果同名文件已存在则移到回收站里
|
IsOverwrite bool // 覆盖已存在的文件,如果同名文件已存在则移到回收站里
|
||||||
|
IsSkipSameName bool // 跳过已存在的文件,即使文件内容不一致(不检查SHA1)
|
||||||
DriveId string
|
DriveId string
|
||||||
ExcludeNames []string // 排除的文件名,包括文件夹和文件。即这些文件/文件夹不进行上传,支持正则表达式
|
ExcludeNames []string // 排除的文件名,包括文件夹和文件。即这些文件/文件夹不进行上传,支持正则表达式
|
||||||
BlockSize int64 // 分片大小
|
BlockSize int64 // 分片大小
|
||||||
@ -92,6 +93,10 @@ var UploadFlags = []cli.Flag{
|
|||||||
Name: "ow",
|
Name: "ow",
|
||||||
Usage: "overwrite, 覆盖已存在的同名文件,注意已存在的文件会被移到回收站",
|
Usage: "overwrite, 覆盖已存在的同名文件,注意已存在的文件会被移到回收站",
|
||||||
},
|
},
|
||||||
|
cli.BoolFlag{
|
||||||
|
Name: "skip",
|
||||||
|
Usage: "skip same name, 跳过已存在的同名文件,即使文件内容不一致(不检查SHA1)",
|
||||||
|
},
|
||||||
cli.BoolFlag{
|
cli.BoolFlag{
|
||||||
Name: "norapid",
|
Name: "norapid",
|
||||||
Usage: "不检测秒传。跳过费时的SHA1计算直接上传",
|
Usage: "不检测秒传。跳过费时的SHA1计算直接上传",
|
||||||
@ -193,6 +198,7 @@ func CmdUpload() cli.Command {
|
|||||||
NoRapidUpload: c.Bool("norapid"),
|
NoRapidUpload: c.Bool("norapid"),
|
||||||
ShowProgress: !c.Bool("np"),
|
ShowProgress: !c.Bool("np"),
|
||||||
IsOverwrite: c.Bool("ow"),
|
IsOverwrite: c.Bool("ow"),
|
||||||
|
IsSkipSameName: c.Bool("skip"),
|
||||||
DriveId: parseDriveId(c),
|
DriveId: parseDriveId(c),
|
||||||
ExcludeNames: c.StringSlice("exn"),
|
ExcludeNames: c.StringSlice("exn"),
|
||||||
BlockSize: int64(c.Int("bs") * 1024),
|
BlockSize: int64(c.Int("bs") * 1024),
|
||||||
@ -441,6 +447,7 @@ func RunUpload(localPaths []string, savePath string, opt *UploadOptions) {
|
|||||||
UploadStatistic: statistic,
|
UploadStatistic: statistic,
|
||||||
ShowProgress: opt.ShowProgress,
|
ShowProgress: opt.ShowProgress,
|
||||||
IsOverwrite: opt.IsOverwrite,
|
IsOverwrite: opt.IsOverwrite,
|
||||||
|
IsSkipSameName: opt.IsSkipSameName,
|
||||||
UseInternalUrl: opt.UseInternalUrl,
|
UseInternalUrl: opt.UseInternalUrl,
|
||||||
GlobalSpeedsStat: globalSpeedsStat,
|
GlobalSpeedsStat: globalSpeedsStat,
|
||||||
FileRecorder: fileRecorder,
|
FileRecorder: fileRecorder,
|
||||||
|
@ -66,6 +66,7 @@ type (
|
|||||||
|
|
||||||
ShowProgress bool
|
ShowProgress bool
|
||||||
IsOverwrite bool // 覆盖已存在的文件,如果同名文件已存在则移到回收站里
|
IsOverwrite bool // 覆盖已存在的文件,如果同名文件已存在则移到回收站里
|
||||||
|
IsSkipSameName bool // 跳过已存在的文件,即使文件内容不一致(不检查SHA1)
|
||||||
|
|
||||||
// 是否使用内置链接
|
// 是否使用内置链接
|
||||||
UseInternalUrl bool
|
UseInternalUrl bool
|
||||||
@ -327,6 +328,7 @@ func (utu *UploadTaskUnit) Run() (result *taskframework.TaskUnitRunResult) {
|
|||||||
|
|
||||||
var apierr *apierror.ApiError
|
var apierr *apierror.ApiError
|
||||||
var rs *aliyunpan.MkdirResult
|
var rs *aliyunpan.MkdirResult
|
||||||
|
var efi *aliyunpan.FileEntity
|
||||||
var appCreateUploadFileParam *aliyunpan.CreateFileUploadParam
|
var appCreateUploadFileParam *aliyunpan.CreateFileUploadParam
|
||||||
var sha1Str string
|
var sha1Str string
|
||||||
var contentHashName string
|
var contentHashName string
|
||||||
@ -398,6 +400,23 @@ StepUploadPrepareUpload:
|
|||||||
proofCode = ""
|
proofCode = ""
|
||||||
contentHashName = "sha1"
|
contentHashName = "sha1"
|
||||||
checkNameMode = "auto_rename"
|
checkNameMode = "auto_rename"
|
||||||
|
// 如果启用了 覆盖/跳过 已存在的文件,则需要提前检查文件是否存在
|
||||||
|
if utu.IsOverwrite || utu.IsSkipSameName {
|
||||||
|
efi, apierr = utu.PanClient.FileInfoByPath(utu.DriveId, utu.SavePath)
|
||||||
|
if apierr != nil && apierr.Code != apierror.ApiCodeFileNotFoundCode {
|
||||||
|
result.Err = apierr
|
||||||
|
result.ResultMessage = "检测同名文件失败"
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if utu.IsSkipSameName {
|
||||||
|
if efi != nil && efi.FileId != "" {
|
||||||
|
result.Succeed = true
|
||||||
|
result.Extra = efi
|
||||||
|
fmt.Printf("[%s] %s 检测到同名文件,跳过上传: %s\n", utu.taskInfo.Id(), time.Now().Format("2006-01-02 15:04:06"), utu.SavePath)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
if !utu.NoRapidUpload {
|
if !utu.NoRapidUpload {
|
||||||
// 计算文件SHA1
|
// 计算文件SHA1
|
||||||
fmt.Printf("[%s] %s 正在计算文件SHA1: %s\n", utu.taskInfo.Id(), time.Now().Format("2006-01-02 15:04:06"), utu.LocalFileChecksum.Path.LogicPath)
|
fmt.Printf("[%s] %s 正在计算文件SHA1: %s\n", utu.taskInfo.Id(), time.Now().Format("2006-01-02 15:04:06"), utu.LocalFileChecksum.Path.LogicPath)
|
||||||
@ -421,12 +440,6 @@ StepUploadPrepareUpload:
|
|||||||
if utu.IsOverwrite {
|
if utu.IsOverwrite {
|
||||||
// 标记覆盖旧同名文件
|
// 标记覆盖旧同名文件
|
||||||
// 检查同名文件是否存在
|
// 检查同名文件是否存在
|
||||||
efi, apierr := utu.PanClient.FileInfoByPath(utu.DriveId, utu.SavePath)
|
|
||||||
if apierr != nil && apierr.Code != apierror.ApiCodeFileNotFoundCode {
|
|
||||||
result.Err = apierr
|
|
||||||
result.ResultMessage = "检测同名文件失败"
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if efi != nil && efi.FileId != "" {
|
if efi != nil && efi.FileId != "" {
|
||||||
if strings.ToUpper(efi.ContentHash) == strings.ToUpper(sha1Str) {
|
if strings.ToUpper(efi.ContentHash) == strings.ToUpper(sha1Str) {
|
||||||
result.Succeed = true
|
result.Succeed = true
|
||||||
|
Loading…
Reference in New Issue
Block a user