Skip to content

Commit e1f49fa

Browse files
authored
Merge pull request #205 from qiniu/develop
v2.3.4
2 parents 6a45882 + b684fec commit e1f49fa

File tree

15 files changed

+153
-70
lines changed

15 files changed

+153
-70
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
# 2.3.4
2+
1. listbucket, listbucket2增加捕捉interrupt信号(CTR-C), 打印marker
3+
2. account在本地记录账号,默认不覆盖, 加了-w强制覆盖选项
4+
3. listbucket2 增加append 模式(-a)开启, 修复列举几亿空间的时候,列举一半左右程序中断问题
5+
4. 修复dircache 列表没有输出到文件使用-o选项的时候
6+
5. 修复qupload, qupload2使用多线程上传导致的部分文件上传失败问题
7+
6. 加了-L 选项到qshell, 使用当前工作路径作为qshell的配置目录
8+
19
# 2.3.3
210
1. 修复qdownload配置cdn_domain使用了测试域名作为HOST 引起超过10G流量限制的问题
311
2. listbucket2 max-retry选项只限制出错下载次数,不限制接口返回空的次数

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ qshell是利用[七牛文档上公开的API](http://developer.qiniu.com)实现
1212
1313
|版本 |支持平台|链接|
1414
|--------|---------|----|
15-
|qshell-v2.3.3 |Mac OSX, Linux, Windows|[下载](http://devtools.qiniu.com/qshell-v2.3.3.zip)|
15+
|qshell-v2.3.4 |Mac OSX, Linux, Windows|[下载](http://devtools.qiniu.com/qshell-v2.3.4.zip)|
1616

1717
## 安装
1818

@@ -69,7 +69,8 @@ $ qshell account <Your AccessKey> <Your SecretKey> <Your Name>
6969
$ qshell account -- <Your AccessKey> <Your SecretKey> <Your Name>
7070
```
7171

72-
可以连续使用qshell account 添加账号ak, sk, name信息,qshell会保存这些账号的信息, 可以使用qshell user命令列举账号信息,在各个账号之间切换, 删除账号等
72+
可以连续使用qshell account 添加账号ak, sk, name信息,qshell会保存这些账号的信息, 可以使用qshell user命令列举账号信息,在各个账号之间切换, 删除账号等。
73+
如果使用的2.3.0之前的版本account命令记录的账户信息,需要先使用qshell user clean清楚保存的账户信息,然后使用qshell account命令重新记录账户信息。
7374

7475
2. 添加完账户后,就可以使用qshell上传,下载文件了
7576

@@ -123,6 +124,7 @@ fi
123124
|-h|打印命令列表帮助信息,遇到参数忘记的情况下,可以使用该命令|
124125
|-v|打印工具版本,反馈问题的时候,请提前告知工具对应版本号|
125126
|-C|qshell配置文件, 其配置格式请看下一节|
127+
|-L|使用当前工作路径作为qshell的配置目录|
126128

127129
## 配置文件
128130

cmd/account.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ import (
77
"os"
88
)
99

10+
var (
11+
accountOver bool
12+
)
13+
1014
func init() {
15+
cmdAccount.Flags().BoolVarP(&accountOver, "overwrite", "w", false, "overwrite account or not when account exists in local db, by default not overwrite")
1116
RootCmd.AddCommand(cmdAccount)
1217
}
1318

@@ -37,7 +42,7 @@ func Account(cmd *cobra.Command, params []string) {
3742
name := params[2]
3843

3944
pt, oldPath := iqshell.AccPath(), iqshell.OldAccPath()
40-
sErr := iqshell.SetAccount2(accessKey, secretKey, name, pt, oldPath)
45+
sErr := iqshell.SetAccount2(accessKey, secretKey, name, pt, oldPath, accountOver)
4146
if sErr != nil {
4247
fmt.Println(sErr)
4348
os.Exit(iqshell.STATUS_ERROR)

cmd/root.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,15 @@ import (
88
"github.com/spf13/viper"
99
"os"
1010
"os/user"
11+
"path/filepath"
1112
"runtime"
1213
)
1314

1415
var (
1516
DebugFlag bool
1617
VersionFlag bool
1718
cfgFile string
19+
local bool
1820
)
1921

2022
const (
@@ -61,8 +63,10 @@ func init() {
6163
RootCmd.PersistentFlags().BoolVarP(&DebugFlag, "debug", "d", false, "debug mode")
6264
RootCmd.PersistentFlags().BoolVarP(&VersionFlag, "version", "v", false, "show version")
6365
RootCmd.PersistentFlags().StringVarP(&cfgFile, "config", "C", "", "config file (default is $HOME/.qshell.json)")
66+
RootCmd.PersistentFlags().BoolVarP(&local, "local", "L", false, "use current directory as config file path")
6467

6568
viper.BindPFlag("config", RootCmd.PersistentFlags().Lookup("config"))
69+
viper.BindPFlag("local", RootCmd.PersistentFlags().Lookup("local"))
6670
}
6771

6872
func initConfig() {
@@ -86,6 +90,32 @@ func initConfig() {
8690
viper.AddConfigPath(curUser.HomeDir)
8791
viper.SetConfigName(".qshell")
8892
}
93+
94+
if local {
95+
dir, gErr := os.Getwd()
96+
if gErr != nil {
97+
fmt.Fprintf(os.Stderr, "get current directory: %v\n", gErr)
98+
os.Exit(1)
99+
}
100+
viper.Set("path.root_path", dir+"/.qshell")
101+
} else {
102+
curUser, gErr := user.Current()
103+
if gErr != nil {
104+
fmt.Fprintf(os.Stderr, "Error: get current user error: %v\n", gErr)
105+
os.Exit(1)
106+
}
107+
viper.Set("path.root_path", curUser.HomeDir+"/.qshell")
108+
}
109+
rootPath := viper.GetString("path.root_path")
110+
111+
viper.SetDefault("path.acc_db_path", filepath.Join(rootPath, "account.db"))
112+
viper.SetDefault("path.acc_path", filepath.Join(rootPath, "account.json"))
113+
viper.SetDefault("hosts.up_host", "upload.qiniup.com")
114+
viper.SetDefault("hosts.rs_host", storage.DefaultRsHost)
115+
viper.SetDefault("hosts.rsf_host", storage.DefaultRsfHost)
116+
viper.SetDefault("hosts.io_host", "iovip.qbox.me")
117+
viper.SetDefault("hosts.api_host", storage.DefaultAPIHost)
118+
89119
if rErr := viper.ReadInConfig(); rErr != nil {
90120
if _, ok := rErr.(viper.ConfigFileNotFoundError); !ok {
91121
fmt.Fprintf(os.Stderr, "read config file: %v\n", rErr)

cmd/rs.go

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ var (
131131
endDate string
132132
maxRetry int
133133
finalKey string
134+
appendMode bool
134135
)
135136

136137
func init() {
@@ -144,10 +145,11 @@ func init() {
144145
lsBucketCmd2.Flags().StringVarP(&listMarker, "marker", "m", "", "list marker")
145146
lsBucketCmd2.Flags().StringVarP(&prefix, "prefix", "p", "", "list by prefix")
146147
lsBucketCmd2.Flags().StringVarP(&suffixes, "suffixes", "q", "", "list by key suffixes, separated by comma")
147-
lsBucketCmd2.Flags().IntVarP(&maxRetry, "max-retry", "x", 20, "max retries when error occurred")
148+
lsBucketCmd2.Flags().IntVarP(&maxRetry, "max-retry", "x", -1, "max retries when error occurred")
148149
lsBucketCmd2.Flags().StringVarP(&outFile, "out", "o", "", "output file")
149150
lsBucketCmd2.Flags().StringVarP(&startDate, "start", "s", "", "start date with format yyyy-mm-dd-hh-MM-ss")
150151
lsBucketCmd2.Flags().StringVarP(&endDate, "end", "e", "", "end date with format yyyy-mm-dd-hh-MM-ss")
152+
lsBucketCmd2.Flags().BoolVarP(&appendMode, "append", "a", false, "append to file")
151153

152154
moveCmd.Flags().BoolVarP(&mOverwrite, "overwrite", "w", false, "overwrite mode")
153155
moveCmd.Flags().StringVarP(&finalKey, "key", "k", "", "filename saved in bucket")
@@ -163,9 +165,8 @@ func init() {
163165
func DirCache(cmd *cobra.Command, params []string) {
164166
var cacheResultFile string
165167
cacheRootPath := params[0]
166-
if len(params) == 2 {
167-
cacheResultFile = params[1]
168-
}
168+
169+
cacheResultFile = outFile
169170
if cacheResultFile == "" {
170171
cacheResultFile = "stdout"
171172
}
@@ -176,10 +177,6 @@ func DirCache(cmd *cobra.Command, params []string) {
176177
}
177178

178179
func ListBucket2(cmd *cobra.Command, params []string) {
179-
if maxRetry <= 0 {
180-
fmt.Fprintf(os.Stderr, "maxRetry must be greater than 0\n")
181-
os.Exit(1)
182-
}
183180
bucket := params[0]
184181

185182
var dateParser = func(datestr string) (time.Time, error) {
@@ -221,7 +218,7 @@ func ListBucket2(cmd *cobra.Command, params []string) {
221218
}
222219
}
223220
bm := iqshell.GetBucketManager()
224-
retErr := bm.ListBucket2(bucket, prefix, listMarker, outFile, "", start, end, sf, maxRetry)
221+
retErr := bm.ListBucket2(bucket, prefix, listMarker, outFile, "", start, end, sf, maxRetry, appendMode)
225222
if retErr != nil {
226223
os.Exit(iqshell.STATUS_ERROR)
227224
}

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.3"
9+
var version = "v2.3.4"
1010

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

docs/account.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
`account`命令用来设置当前用户的`AccessKey``SecretKey`,这对Key主要用在其他的需要授权的命令中,比如`stat`,`delete`,`listbucket`命令中。
44
该命令设置的信息,经过加密保存在命令执行的目录下的`.qshell/account.json`文件中。
55

6+
本地数据库会记录`account`注册的所有<AccessKey>, <SecretKey> 和<Name>的信息, 所以当用`account`注册账户信息时,如果qshell发现本地数据库有同样的名字为
7+
<Name>的账户, 那么默认qshell会返回错误信息报告该名字的账户已经存在,如果要覆盖注册,需要使用强制覆盖选项--overwrite 或者 -w
8+
69
# 格式
710

811
```
@@ -12,18 +15,21 @@ qshell account
1215
打印当前设置的`AccessKey`, `SecretKey``Name`
1316

1417
```
15-
qshell account <Your AccessKey> <Your SecretKey> <Your Account Name>
18+
qshell account [--overwrite | -w]<Your AccessKey> <Your SecretKey> <Your Account Name>
1619
```
1720

18-
设置当前用户的`AccessKey`, `SecretKey``Name`
21+
设置当前用户的`AccessKey`, `SecretKey``Name`, Name是用户可以任意取的名字,表示当前在本地记录的账户的名称,和在七牛注册的邮箱信息没有关系
22+
23+
# 选项
24+
-w --overwrite 强制覆盖已经存在的账户
1925

2026
# 参数
2127

2228
|参数名|描述|
2329
|--------|--------|
2430
|AccessKey|七牛账号对应的AccessKey [获取](https://portal.qiniu.com/user/key)|
2531
|SecretKey|七牛账号对应的SecretKey [获取](https://portal.qiniu.com/user/key)|
26-
|Name|账户的名字|
32+
|Name|账户的名字, 可以任意取,和在七牛注册的邮箱信息没有关系, 只是qshell本地用来标示<ak, sk>对 |
2733

2834
# 示例
2935

docs/cdnrefresh.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ qshell cdnrefresh [-i <UrlListFile>]
1313
刷新目录的命令格式:
1414

1515
```
16-
qshell cdnrefresh --dirs <DirListFile>
16+
qshell cdnrefresh --dirs -i <DirListFile>
1717
```
1818

1919
注意需要刷新的目录,必须以`/`结尾。如果没有制定输入文件<UrlListFile>默认从终端读取输入内容

docs/listbucket2.md

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Key\tSize\tHash\tPutTime\tMimeType\tFileType\tEndUser
1515
# 格式
1616

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

2121
# 鉴权
@@ -32,8 +32,9 @@ qshell listbucket2 [--prefix <Prefix> | --suffixes <suffixes1,suffixes2>] [--sta
3232
| ListBucketResultFile | 获取的文件列表保存在本地的文件名,如果不指定该参数,则会把结果输出到终端,一般可用于获取小规模文件列表测试使用 | Y |
3333
| StartDate | 列举整个空间,然后从中筛选出文件上传日期在<StartDate>之后的文件 | Y |
3434
| EndDate | 列举整个空间, 然后从中筛选出文件上传日期在<EndDate>之前的文件 | Y |
35-
| RetryCount | 列举整个空间文件出错以后,最大的尝试次数;超过最大尝试次数以后,程序退出,打印出marker | Y |
36-
| suffixes | 列举整个空间文件, 然后从中筛选出文件后缀为在[suffixes1, suffixes2, ...]中的文件 |Y|
35+
| RetryCount | 列举整个空间文件出错以后,最大的尝试次数;超过最大尝试次数以后,程序退出,打印出marker | Y |
36+
| suffixes | 列举整个空间文件, 然后从中筛选出文件后缀为在[suffixes1, suffixes2, ...]中的文件 | Y |
37+
| a | 开启选项o 的append模式, 如果本地保存文件列表的文件已经存在,如果希望像该文件添加内容,使用该选项, 必须和-o选项一起使用 | Y |
3738

3839

3940
# 常用使用场景介绍
@@ -43,31 +44,37 @@ qshell listbucket2 [--prefix <Prefix> | --suffixes <suffixes1,suffixes2>] [--sta
4344
```
4445
qshell listbucket2 <Bucket> -o <ListBucketResultFile>
4546
```
47+
48+
(2) 如果本地文件`ListBucketResultFile`已经存在,有上一次列举的内容,如果希望把新的列表添加到该文件中,需要使用选项-a开启-o选项的append 模式
49+
50+
```
51+
qshell listbucket2 <Bucket> -a -o <ListBucketResultFile>
52+
```
4653

47-
(2) 获取空间所有文件,输出到屏幕上(标准输出)
54+
(3) 获取空间所有文件,输出到屏幕上(标准输出)
4855

4956
```
5057
qshell listbucket2 <Bucket>
5158
```
5259

53-
3)获取空间中指定前缀的文件列表
60+
4)获取空间中指定前缀的文件列表
5461

5562
```
5663
qshell listbucket2 [--prefix <Prefix>] <Bucket> -o <ListBucketResultFile>
5764
```
5865

59-
(4) 获取空间中指定前缀的文件列表, 输出到屏幕上
66+
(5) 获取空间中指定前缀的文件列表, 输出到屏幕上
6067

6168
```
6269
qshell listbucket2 [--prefix <Prefix>] <Bucket>
6370
```
6471

65-
(5) 获取2018-10-30到2018-11-02上传的文件
72+
(6) 获取2018-10-30到2018-11-02上传的文件
6673
```
6774
qshell listbucket2 --start 2018-10-30 --end 2018-11-02 <Bucket>
6875
```
6976

70-
(6) 获取后缀为mp4, html的文件
77+
(7) 获取后缀为mp4, html的文件
7178

7279
```
7380
qshell listbucket2 --suffixes mp4,html <Bucket>

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
github.com/inconshreveable/mousetrap v1.0.0 // indirect
1010
github.com/onsi/gomega v1.4.2 // indirect
1111
github.com/pmezard/go-difflib v1.0.0 // indirect
12-
github.com/qiniu/api.v7 v7.2.5-0.20181112070011-bc6998c1186a+incompatible
12+
github.com/qiniu/api.v7 v7.2.6-0.20181128092015-8c3e1ca2eb33+incompatible
1313
github.com/qiniu/x v7.0.8+incompatible // indirect
1414
github.com/satori/go.uuid v1.2.0 // indirect
1515
github.com/spf13/cobra v0.0.3

0 commit comments

Comments
 (0)