Skip to content

Commit dd1d5b3

Browse files
committed
add filter directory
1 parent 4ecb8f1 commit dd1d5b3

File tree

14 files changed

+2682
-186
lines changed

14 files changed

+2682
-186
lines changed

lib/command_test.go

Lines changed: 499 additions & 35 deletions
Large diffs are not rendered by default.

lib/cp.go

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ type copyOptionType struct {
6969
type filterOptionType struct {
7070
name string
7171
pattern string
72+
isDir bool
7273
}
7374

7475
type fileInfoType struct {
@@ -210,7 +211,6 @@ var specChineseCopy = SpecText{
210211
?:匹配单个字符
211212
[sequence]:匹配sequence的任意字符
212213
[!sequence]:匹配不在sequence的任意字符
213-
注意:规则不支持带目录的格式,e.g.,--include "/usr/*/test/*.jpg"。
214214
215215
--include和--exclude可以出现多次。当多个规则出现时,这些规则按从左往右的顺序应用。例如:
216216
当前目录下包含3个文件:
@@ -229,6 +229,23 @@ var specChineseCopy = SpecText{
229229
$ ossutil cp . oss://my-bucket/path --exclude '*.jpg' --include 'testfile*.jpg' --exclude 'testfile?.jpg'
230230
上传testfile2.txt到oss://my-bucket/path/testfile2.txt
231231
上传testfile33.jpg到oss://my-bucket/path/testfile33.jpg
232+
233+
当前目录下包含3个文件一个目录:
234+
testfile1.jpg
235+
testfiel2.txt
236+
testfile33.jpg
237+
testdir1
238+
-testfile1.txt
239+
-testfile2.txt
240+
-testfile3.txt
241+
$ ossutil cp . oss://my-bucket/path --include 'testdir1/*'
242+
上传testdir1目录下的文件到oss://my-bucket/path/testdir1/
243+
244+
$ ossutil cp . oss://my-bucket/path --exclude 'testdir1/*'
245+
上传testfile1.jpg到oss://my-bucket/path/testfile1.jpg
246+
上传testfile2.txt到oss://my-bucket/path/testfile2.txt
247+
上传testfile33.jpg到oss://my-bucket/path/testfile33.jpg
248+
232249
233250
--meta选项
234251
@@ -736,7 +753,6 @@ var specEnglishCopy = SpecText{
736753
?: Matches any single character
737754
[sequence]: Matches any character in sequence
738755
[!sequence]: Matches any character not in sequence
739-
Note: does not support patterns containing directory info. e.g., --include "/usr/*/test/*.jpg"
740756
741757
Any number of these parameters can be passed to a command. You can do this by providing an --exclude
742758
or --include argument multiple times, e.g.,
@@ -767,6 +783,22 @@ var specEnglishCopy = SpecText{
767783
upload testfile2.txt to oss://my-bucket/path/testfile2.txt
768784
upload testfile33.jpg to oss://my-bucket/path/testfile33.jpg
769785
786+
e.g., 3 files in current dir and 1 subdir
787+
testfile1.jpg
788+
testfiel2.txt
789+
testfile33.jpg
790+
testdir1
791+
-testfile1.txt
792+
-testfile2.txt
793+
-testfile3.txt
794+
$ ossutil cp . oss://my-bucket/path --include 'testdir1/*'
795+
upload files in testdir1 directory to oss://my-bucket/path/testdir1/
796+
797+
$ ossutil cp . oss://my-bucket/path --exclude 'testdir1/*'
798+
upload testfile1.jpg to oss://my-bucket/path/testfile1.jpg
799+
upload testfile2.txt to oss://my-bucket/path/testfile2.txt
800+
upload testfile33.jpg to oss://my-bucket/path/testfile33.jpg
801+
770802
--meta option
771803
772804
This option will set the specified objects' meta data. If --recursive option is specified,
@@ -1769,7 +1801,10 @@ func (cc *CopyCommand) getFileListStatistic(dpath string) error {
17691801

17701802
if f.IsDir() {
17711803
if fpath != dpath {
1772-
cc.monitor.updateScanNum(1)
1804+
if doesSingleFileMatchPatterns(fpath, cc.cpOption.filters) {
1805+
cc.monitor.updateScanNum(1)
1806+
}
1807+
17731808
}
17741809
return nil
17751810
}
@@ -1803,7 +1838,7 @@ func (cc *CopyCommand) getFileListStatistic(dpath string) error {
18031838
return nil
18041839
}
18051840
}
1806-
if doesSingleFileMatchPatterns(f.Name(), cc.cpOption.filters) {
1841+
if doesSingleFileMatchPatterns(fpath, cc.cpOption.filters) {
18071842
cc.monitor.updateScanSizeNum(realFileSize, 1)
18081843
}
18091844
return nil
@@ -1903,11 +1938,14 @@ func (cc *CopyCommand) getFileList(dpath string, chFiles chan<- fileInfoType) er
19031938

19041939
if f.IsDir() {
19051940
if fpath != dpath {
1906-
if strings.HasSuffix(fileName, "\\") || strings.HasSuffix(fileName, "/") {
1907-
chFiles <- fileInfoType{fileName, name}
1908-
} else {
1909-
chFiles <- fileInfoType{fileName + string(os.PathSeparator), name}
1941+
if doesSingleFileMatchPatterns(fpath, cc.cpOption.filters) {
1942+
if strings.HasSuffix(fileName, "\\") || strings.HasSuffix(fileName, "/") {
1943+
chFiles <- fileInfoType{fileName, name}
1944+
} else {
1945+
chFiles <- fileInfoType{fileName + string(os.PathSeparator), name}
1946+
}
19101947
}
1948+
19111949
}
19121950
return nil
19131951
}
@@ -1934,8 +1972,7 @@ func (cc *CopyCommand) getFileList(dpath string, chFiles chan<- fileInfoType) er
19341972
return nil
19351973
}
19361974
}
1937-
1938-
if doesSingleFileMatchPatterns(fileName, cc.cpOption.filters) {
1975+
if doesSingleFileMatchPatterns(fpath, cc.cpOption.filters) {
19391976
chFiles <- fileInfoType{fileName, name}
19401977
}
19411978
return nil
@@ -2369,7 +2406,6 @@ func (cc *CopyCommand) downloadFiles(srcURL CloudURL, destURL FileURL) error {
23692406
prefix = srcURL.object[:index+1]
23702407
relativeKey = srcURL.object[index+1:]
23712408
}
2372-
23732409
go cc.objectStatistic(bucket, srcURL)
23742410
err := cc.downloadSingleFileWithReport(bucket, objectInfoType{prefix, relativeKey, -1, time.Now()}, filePath)
23752411
return cc.formatResultPrompt(err)

0 commit comments

Comments
 (0)