Skip to content

Commit 7bef813

Browse files
authored
Merge pull request #200 from tonycai653/master
修复一些bug, 给listbucket2加无限重试的功能,用于列举大量删除文件的情况
2 parents cc15dac + 26f7d8a commit 7bef813

16 files changed

+71
-24
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
# 2.3.2
2+
1. 修复fetch incorrect region
3+
2. 修复docs中文档格式显示问题
4+
3. 给listbucket2添加不限制重试次数的功能
5+
16
# 2.3.1
27
1. batchdelete, batchchgm, batchchtype, batchmove, batchrename命令运行可导出失败,成功文件列表
38
2. rput, fput, qupload上传支持设置回调用

README.md

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,24 +49,30 @@ export PATH=$PATH:/home/jemy/tools
4949

5050
![windows-qshell-path-settings.png](http://devtools.qiniu.com/windows-qshell-path-settings.png)
5151

52-
## 密钥设置
52+
## qshell使用
53+
54+
1. 添加密钥和账户名称
5355

5456
该工具有两类命令,一类需要鉴权,另一类不需要。
5557

56-
需要鉴权的命令都需要依赖七牛账号下的 `AccessKey``SecretKey`。所以这类命令运行之前,需要使用 `account` 命令来设置下 `AccessKey``SecretKey`
58+
需要鉴权的命令都需要依赖七牛账号下的 `AccessKey`, `SecretKey``Name`。所以这类命令运行之前,需要使用 `account` 命令来添加 `AccessKey``SecretKey``Name`
59+
`Name`是用户可以自定义的字符串,用来唯一表示AccessKey/SecretKey账户,qshell会对添加的每一个账户信息加密保存,可以使用自命令`user`进行切换,切换账户的时候,需要使用账户唯一标识
60+
`Name`
5761

5862
```
59-
$ qshell account ak sk name
63+
$ qshell account <Your AccessKey> <Your SecretKey> <Your Name>
6064
```
6165

6266
其中name表示该账号的名称, 如果ak, sk, name首字母是"-", 需要使用如下的方式添加账号, 这样避免把该项识别成命令行选项:
6367

6468
```
65-
$ qshell account -- ak sk name
69+
$ qshell account -- <Your AccessKey> <Your SecretKey> <Your Name>
6670
```
6771

6872
可以连续使用qshell account 添加账号ak, sk, name信息,qshell会保存这些账号的信息, 可以使用qshell user命令列举账号信息,在各个账号之间切换, 删除账号等
6973

74+
2. 添加完账户后,就可以使用qshell上传,下载文件了
75+
7076
## 账户管理
7177

7278
使用qshell user子命令可以用来管理记录的多账户信息。

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
}

cmd/version.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"runtime"
77
)
88

9-
var version = "v2.3.1"
9+
var version = "v2.3.2"
1010

1111
var versionCmd = &cobra.Command{
1212
Use: "version",

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

0 commit comments

Comments
 (0)