Skip to content

Commit c1acf0e

Browse files
committed
cp supports start-time and end-time options.
1 parent 2950c55 commit c1acf0e

File tree

1 file changed

+59
-8
lines changed

1 file changed

+59
-8
lines changed

lib/cp.go

Lines changed: 59 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ type copyOptionType struct {
6464
tagging string
6565
opType operationType
6666
bSyncCommand bool
67+
startTime int64
68+
endTime int64
6769
}
6870

6971
type filterOptionType struct {
@@ -350,6 +352,13 @@ var specChineseCopy = SpecText{
350352
和-r选项一起使用,表示只操作当前目录下的文件, 会忽略当前目录下的子目录, 如果是下载或者拷贝oss
351353
的目录,目录后面要加上反斜线/
352354
355+
--start-time
356+
时间戳, 既从1970年1月1日(UTC/GMT的午夜)开始所经过的秒数
357+
如果输入这个选项, 文件的最后修改时间小于该时间戳将被忽略
358+
359+
--end-time
360+
时间戳, 既从1970年1月1日(UTC/GMT的午夜)开始所经过的秒数
361+
如果输入这个选项, 文件的最后修改时间大于该时间戳将被忽略
353362
354363
大文件断点续传:
355364
@@ -893,20 +902,30 @@ Other Options:
893902
894903
--enable-symlink-dir option
895904
896-
Allows transfer of files in the link subdirectory. If there is an infinite loop link file or directory,
897-
it will cause an error.
898-
It is recommended to use the probe command to detect the existence of an infinite loop link file or
899-
directory before use
905+
Allows transfer of files in the link subdirectory. If there is an infinite loop link file or directory,
906+
it will cause an error.
907+
It is recommended to use the probe command to detect the existence of an infinite loop link file or
908+
directory before use
900909
901910
--disable-all-symlink option
902911
903-
specifies that uploading of symlink files and symlink directories under the directory is not allowed
912+
specifies that uploading of symlink files and symlink directories under the directory is not allowed
904913
905914
--only-current-dir
906915
907-
Used with the -r option, it means that only the files in the current directory will be manipulated,
908-
and the subdirectories under the current directory will be ignored.
909-
If you are downloading or copying the oss directory, add a backslash(/) after the directory.
916+
Used with the -r option, it means that only the files in the current directory will be manipulated,
917+
and the subdirectories under the current directory will be ignored.
918+
If you are downloading or copying the oss directory, add a backslash(/) after the directory.
919+
920+
--start-time
921+
922+
Timestamp, the number of seconds that elapsed from January 1, 1970 (midnight UTC/GMT).
923+
If this option is set, do not transfer files that have last modified time less than this.
924+
925+
--end-time
926+
927+
Timestamp, the number of seconds that elapsed from January 1, 1970 (midnight UTC/GMT).
928+
If this option is set, do not transfer files that have last modified time greater than this.
910929
911930
Resume copy of big file:
912931
@@ -1295,6 +1314,8 @@ var copyCommand = CopyCommand{
12951314
OptionRegion,
12961315
OptionCloudBoxID,
12971316
OptionForcePathStyle,
1317+
OptionStartTime,
1318+
OptionEndTime,
12981319
},
12991320
},
13001321
}
@@ -1359,6 +1380,12 @@ func (cc *CopyCommand) RunCommand() error {
13591380
LogInfo("filter %d,name:%s,pattern:%s\n", k, v.name, v.pattern)
13601381
}
13611382

1383+
cc.cpOption.startTime, _ = GetInt(OptionStartTime, cc.command.options)
1384+
cc.cpOption.endTime, _ = GetInt(OptionEndTime, cc.command.options)
1385+
if cc.cpOption.endTime > 0 && cc.cpOption.startTime > cc.cpOption.endTime {
1386+
return fmt.Errorf("start time %d is larger than end time %d", cc.cpOption.startTime, cc.cpOption.endTime)
1387+
}
1388+
13621389
//get file list
13631390
srcURLList, err := cc.getStorageURLs(cc.command.args[0 : len(cc.command.args)-1])
13641391
if err != nil {
@@ -2113,6 +2140,14 @@ func (cc *CopyCommand) makeObjectName(destURL CloudURL, file fileInfoType) strin
21132140
}
21142141

21152142
func (cc *CopyCommand) skipUpload(spath string, bucket *oss.Bucket, objectName string, destURL CloudURL, srcModifiedTime int64) (bool, error) {
2143+
if cc.cpOption.startTime > 0 && srcModifiedTime < cc.cpOption.startTime {
2144+
return true, nil
2145+
}
2146+
2147+
if cc.cpOption.endTime > 0 && srcModifiedTime > cc.cpOption.endTime {
2148+
return true, nil
2149+
}
2150+
21162151
if cc.cpOption.snapshotPath != "" || cc.cpOption.update {
21172152
if cc.cpOption.snapshotPath != "" {
21182153
tstr, err := cc.cpOption.snapshotldb.Get([]byte(spath), nil)
@@ -2522,6 +2557,14 @@ func (cc *CopyCommand) makeFileName(relativeObject, filePath string) string {
25222557
}
25232558

25242559
func (cc *CopyCommand) skipDownload(fileName string, srcModifiedTime time.Time, object string) bool {
2560+
if cc.cpOption.startTime > 0 && srcModifiedTime.Unix() < cc.cpOption.startTime {
2561+
return true
2562+
}
2563+
2564+
if cc.cpOption.endTime > 0 && srcModifiedTime.Unix() > cc.cpOption.endTime {
2565+
return true
2566+
}
2567+
25252568
if cc.cpOption.snapshotPath != "" || cc.cpOption.update {
25262569
if cc.cpOption.snapshotPath != "" {
25272570
tstr, err := cc.cpOption.snapshotldb.Get([]byte(object), nil)
@@ -2986,6 +3029,14 @@ func (cc *CopyCommand) makeCopyObjectName(srcRelativeObject, destObject string)
29863029
}
29873030

29883031
func (cc *CopyCommand) skipCopy(destURL CloudURL, destObject string, srct time.Time) (bool, error) {
3032+
if cc.cpOption.startTime > 0 && srct.Unix() < cc.cpOption.startTime {
3033+
return true, nil
3034+
}
3035+
3036+
if cc.cpOption.endTime > 0 && srct.Unix() > cc.cpOption.endTime {
3037+
return true, nil
3038+
}
3039+
29893040
destBucket, err := cc.command.ossBucket(destURL.bucket)
29903041
if err != nil {
29913042
return false, err

0 commit comments

Comments
 (0)