Skip to content

Commit 11d3772

Browse files
committed
fix bugs in fetch and add support for no limit on v2 list
1 parent b243e6a commit 11d3772

File tree

13 files changed

+55
-19
lines changed

13 files changed

+55
-19
lines changed

cmd/root.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,5 +86,9 @@ func initConfig() {
8686
viper.AddConfigPath(curUser.HomeDir)
8787
viper.SetConfigName(".qshell")
8888
}
89-
viper.ReadInConfig()
89+
if rErr := viper.ReadInConfig(); rErr != nil {
90+
if _, ok := rErr.(viper.ConfigFileNotFoundError); !ok {
91+
fmt.Fprintf(os.Stderr, "read config file: %v\n", rErr)
92+
}
93+
}
9094
}

cmd/rs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ func init() {
144144
lsBucketCmd2.Flags().StringVarP(&listMarker, "marker", "m", "", "list marker")
145145
lsBucketCmd2.Flags().StringVarP(&prefix, "prefix", "p", "", "list by prefix")
146146
lsBucketCmd2.Flags().StringVarP(&suffixes, "suffixes", "q", "", "list by key suffixes, separated by comma")
147-
lsBucketCmd2.Flags().IntVarP(&maxRetry, "max-retry", "x", 5, "max retries when error occurred")
147+
lsBucketCmd2.Flags().IntVarP(&maxRetry, "max-retry", "x", 20, "max retries when error occurred")
148148
lsBucketCmd2.Flags().StringVarP(&outFile, "out", "o", "", "output file")
149149
lsBucketCmd2.Flags().StringVarP(&startDate, "start", "s", "", "start date with format yyyy-mm-dd-hh-MM-ss")
150150
lsBucketCmd2.Flags().StringVarP(&endDate, "end", "e", "", "end date with format yyyy-mm-dd-hh-MM-ss")

cmd/rsbatch.go

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,10 @@ var (
109109

110110
func init() {
111111
batchFetchCmd.Flags().StringVarP(&inputFile, "input-file", "i", "", "urls list file")
112-
batchFetchCmd.Flags().IntVarP(&worker, "worker", "c", 5, "worker count")
112+
batchFetchCmd.Flags().IntVarP(&worker, "worker", "c", 1, "worker count")
113+
batchFetchCmd.Flags().StringVarP(&bsuccessFname, "success-list", "s", "", "file to save batch fetch success list")
114+
batchFetchCmd.Flags().StringVarP(&bfailureFname, "failure-list", "e", "", "file to save batch fetch failure list")
115+
113116
batchStatCmd.Flags().StringVarP(&inputFile, "input-file", "i", "", "input file")
114117
batchCopyCmd.Flags().StringVarP(&inputFile, "input-file", "i", "", "input file")
115118
batchMoveCmd.Flags().StringVarP(&inputFile, "input-file", "i", "", "input file")
@@ -195,11 +198,16 @@ func BatchFetch(cmd *cobra.Command, params []string) {
195198
)
196199
defer close(fItemChan)
197200

198-
go batchFetch(fItemChan)
201+
fileExporter, fErr := iqshell.NewFileExporter(bsuccessFname, bfailureFname, "")
202+
if fErr != nil {
203+
fmt.Fprintf(os.Stderr, "create file exporter: %v\n", fErr)
204+
os.Exit(1)
205+
}
206+
go batchFetch(fItemChan, fileExporter)
199207

200208
for scanner.Scan() {
201209
line := scanner.Text()
202-
items := strings.Fields(line)
210+
items := strings.Split(line, "\t")
203211
if len(items) <= 0 {
204212
continue
205213
}
@@ -225,13 +233,24 @@ func BatchFetch(cmd *cobra.Command, params []string) {
225233
}
226234
}
227235

228-
func batchFetch(fItemChan chan *iqshell.FetchItem) {
236+
func batchFetch(fItemChan chan *iqshell.FetchItem, fileExporter *iqshell.FileExporter) {
229237
for i := 0; i < worker; i++ {
230238
go func() {
231239
bm := iqshell.GetBucketManager()
232240
for fetchItem := range fItemChan {
233-
fetchResult, fErr := bm.Fetch(fetchItem.RemoteUrl, fetchItem.Bucket, fetchItem.Key)
234-
fmt.Println(fetchResult, fErr)
241+
_, fErr := bm.Fetch(fetchItem.RemoteUrl, fetchItem.Bucket, fetchItem.Key)
242+
if fErr != nil {
243+
fmt.Fprintf(os.Stderr, "fetch %s => %s:%s failed\n", fetchItem.RemoteUrl, fetchItem.Bucket, fetchItem.Key)
244+
if fileExporter != nil {
245+
fileExporter.WriteToFailedWriter(fmt.Sprintf("%s\t%s\t%v\n", fetchItem.RemoteUrl, fetchItem.Key, fErr))
246+
}
247+
} else {
248+
fmt.Printf("fetch %s => %s:%s success\n", fetchItem.RemoteUrl, fetchItem.Bucket, fetchItem.Key)
249+
if fileExporter != nil {
250+
fileExporter.WriteToSuccessWriter(fmt.Sprintf("%s\t%s\n", fetchItem.RemoteUrl, fetchItem.Key))
251+
}
252+
253+
}
235254
}
236255
}()
237256
}

docs/batchcopy.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ qshell batchcopy [--force] [--overwrite] [--success-list <SuccessFileName>] [--f
1414
# 帮助
1515
```
1616
qshell batchcopy -h
17-
``**
17+
```
1818

1919
# 鉴权
2020

docs/batchdelete.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ qshell batchdelete [--force] [--success-list <SuccessFileName>] [--failure-list
1111
# 帮助
1212
```
1313
qshell batchdelete -h
14-
``**
14+
```
1515

1616
# 鉴权
1717

docs/batchexpire.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ qshell batchexpire [--force] <Bucket> <-i KeyDeleteAfterDaysMapFile>
1212
# 帮助
1313
```
1414
qshell batchexpire -h
15-
``**
15+
```
1616

1717
# 鉴权
1818

docs/batchrename.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
```
1111
qshell batchrename [--force] [--overwrite] [--success-list <SuccessFileName>] [--failure-list <failureFileName>] <Bucket> [-i <OldNewKeyMapFile>]
12-
`****
12+
```
1313

1414
# 鉴权
1515

docs/batchsign.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
```
88
qshell batchsign [<-i UrlListFile>] [-e <Deadline>]
9-
``**
9+
```
1010

1111
# 鉴权
1212

docs/batchstat.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
```
88
qshell batchstat <Bucket> <-i KeyListFile>
9-
``**
9+
```
1010

1111
# 鉴权
1212

docs/listbucket2.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ Key\tSize\tHash\tPutTime\tMimeType\tFileType\tEndUser
1515
# 格式
1616

1717
```
18-
qshell listbucket2 [--prefix <Prefix> | --suffixes <suffixes1,suffixes2>] [--start <StartDate>] [--end <EndDate>] <Bucket> [-o <ListBucketResultFile>]
18+
qshell listbucket2 [--prefix <Prefix> | --suffixes <suffixes1,suffixes2>] [--start <StartDate>] [--max-retry <RetryCount>][--end <EndDate>] <Bucket> [-o <ListBucketResultFile>]
1919
```
2020

21+
选项max-retry, 默认列举出错的重试次数为20次,如果希望可以列举完文件列表,不限错误次数,可以设置max-retry为负数。
22+
2123
(1)获取空间中所有的文件列表,这种情况下,可以直接指定 `Bucket` 参数和结果保存文件参数 `ListBucketResultFile` 即可。
2224

2325
```

0 commit comments

Comments
 (0)