Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 75 additions & 21 deletions lib/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ var (
downloadFileName = "ossutil_test.download_file" + randStr(5)
downloadDir = "ossutil_test.download_dir" + randStr(5)
inputFileName = "ossutil_test.input_file" + randStr(5)
objectFileName = "ossutil_test.object_file" + randStr(5)
content = "abc"
cm = CommandManager{}
out = os.Stdout
Expand Down Expand Up @@ -1415,6 +1416,16 @@ func (s *OssutilCommandSuite) initSetMetaWithArgs(args []string, cmdline string,
cmdline = cmdline[0:pos] + cmdline[pos+len("--delete"):]
}

var disableIgnoreError bool
if pos := strings.Index(cmdline, "--disable-ignore-error"); pos != -1 {
disableIgnoreError = true
cmdline = cmdline[0:pos] + cmdline[pos+len("--disable-ignore-error"):]
}

objectFile := ""
snapshotPath := ""
objectFile, snapshotPath, cmdline = s.handleObjectFileSnapshot(cmdline)

parameter := strings.Split(cmdline, "-")
r := false
f := false
Expand All @@ -1426,17 +1437,20 @@ func (s *OssutilCommandSuite) initSetMetaWithArgs(args []string, cmdline string,
str := ""
routines := strconv.Itoa(Routines)
options := OptionMapType{
"endpoint": &str,
"accessKeyID": &str,
"accessKeySecret": &str,
"stsToken": &str,
"configFile": &configFile,
"update": &update,
"delete": &delete,
"recursive": &r,
"force": &f,
"routines": &routines,
"encodingType": &encodingType,
"endpoint": &str,
"accessKeyID": &str,
"accessKeySecret": &str,
"stsToken": &str,
"configFile": &configFile,
"update": &update,
"delete": &delete,
"recursive": &r,
"force": &f,
"routines": &routines,
"encodingType": &encodingType,
"objectFile": &objectFile,
"snapshotPath": &snapshotPath,
"disableIgnoreError": &disableIgnoreError,
}
err := setMetaCommand.Init(args, options)
return err
Expand Down Expand Up @@ -1582,13 +1596,50 @@ func (s *OssutilCommandSuite) getFileList(dpath string) ([]string, error) {
return fileList, err
}

func (s *OssutilCommandSuite) handleObjectFileSnapshot(cmdline string) (objectFile, snapshotPath, newCmdline string) {
cmds := strings.Split(cmdline, " ")
for i := 0; i < len(cmds); i++ {
if cmds[i] == "--object-file" && !strings.HasPrefix(cmds[i+1], "-") {
objectFile = cmds[i+1]
} else {
continue
}
cmds = append(cmds[:i], cmds[i+2:]...)
}
for i := 0; i < len(cmds); i++ {
if cmds[i] == "--snapshot-path" && !strings.HasPrefix(cmds[i+1], "-") {
snapshotPath = cmds[i+1]
} else {
continue
}
cmds = append(cmds[:i], cmds[i+2:]...)
}

// remake cmdline
cmdline = ""
for i := 0; i < len(cmds); i++ {
cmdline = cmdline + " " + cmds[i]
}
return objectFile, snapshotPath, cmdline
}

func (s *OssutilCommandSuite) initRestoreObject(args []string, cmdline string, outputDir string) error {
encodingType := ""
if pos := strings.Index(cmdline, "--encoding-type url"); pos != -1 {
encodingType = URLEncodingType
cmdline = cmdline[0:pos] + cmdline[pos+len("--encoding-type url"):]
}

var disableIgnoreError bool
if pos := strings.Index(cmdline, "--disable-ignore-error"); pos != -1 {
disableIgnoreError = true
cmdline = cmdline[0:pos] + cmdline[pos+len("--disable-ignore-error"):]
}

objectFile := ""
snapshotPath := ""
objectFile, snapshotPath, cmdline = s.handleObjectFileSnapshot(cmdline)

parameter := strings.Split(cmdline, "-")
r := false
f := false
Expand All @@ -1600,16 +1651,19 @@ func (s *OssutilCommandSuite) initRestoreObject(args []string, cmdline string, o
str := ""
routines := strconv.Itoa(Routines)
options := OptionMapType{
"endpoint": &str,
"accessKeyID": &str,
"accessKeySecret": &str,
"stsToken": &str,
"configFile": &configFile,
"recursive": &r,
"force": &f,
"encodingType": &encodingType,
"routines": &routines,
"outputDir": &outputDir,
"endpoint": &str,
"accessKeyID": &str,
"accessKeySecret": &str,
"stsToken": &str,
"configFile": &configFile,
"recursive": &r,
"force": &f,
"encodingType": &encodingType,
"routines": &routines,
"outputDir": &outputDir,
"objectFile": &objectFile,
"snapshotPath": &snapshotPath,
"disableIgnoreError": &disableIgnoreError,
}
err := restoreCommand.Init(args, options)
return err
Expand Down
1 change: 1 addition & 0 deletions lib/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ const (
OptionSkipVerfiyCert = "skipVerifyCert"
OptionItem = "item"
OptionUserAgent = "userAgent"
OptionObjectFile = "objectFile"
)

// the elements show in stat object
Expand Down
16 changes: 10 additions & 6 deletions lib/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Monitorer interface {
type MonitorSnap struct {
okNum int64
errNum int64
skipNum int64
dealNum int64
}

Expand All @@ -49,6 +50,7 @@ type Monitor struct {
totalNum int64
okNum int64
errNum int64
skipNum int64
seekAheadError error
seekAheadEnd bool
finish bool
Expand All @@ -62,6 +64,7 @@ func (m *Monitor) init(opStr string) {
m.seekAheadError = nil
m.okNum = 0
m.errNum = 0
m.skipNum = 0
m.finish = false
}

Expand Down Expand Up @@ -90,6 +93,7 @@ func (m *Monitor) getSnapshot() *MonitorSnap {
var snap MonitorSnap
snap.okNum = m.okNum
snap.errNum = m.errNum
snap.skipNum = m.skipNum
snap.dealNum = snap.okNum + snap.errNum
return &snap
}
Expand Down Expand Up @@ -141,24 +145,24 @@ func (m *Monitor) getWholeFinishBar() string {
snap := m.getSnapshot()
if m.seekAheadEnd && m.seekAheadError == nil {
if snap.errNum == 0 {
return getClearStr(fmt.Sprintf("Succeed: Total %d objects. %s %d objects.\n", m.totalNum, m.opStr, snap.okNum))
return getClearStr(fmt.Sprintf("Succeed: Total %d objects. %s %d objects(skip %d objects).\n", m.totalNum, m.opStr, snap.okNum, snap.skipNum))
}
return getClearStr(fmt.Sprintf("FinishWithError: Total %d objects. %s %d objects, Error %d objects.\n", m.totalNum, m.opStr, snap.okNum, snap.errNum))
return getClearStr(fmt.Sprintf("FinishWithError: Total %d objects. %s %d objects(skip %d objects), Error %d objects.\n", m.totalNum, m.opStr, snap.okNum, snap.skipNum, snap.errNum))
}
scanNum := max(m.totalNum, snap.dealNum)
if snap.errNum == 0 {
return getClearStr(fmt.Sprintf("Succeed: Total %d objects. %s %d objects.\n", scanNum, m.opStr, snap.okNum))
return getClearStr(fmt.Sprintf("Succeed: Total %d objects. %s %d objects(skip %d objects).\n", scanNum, m.opStr, snap.okNum, snap.skipNum))
}
return getClearStr(fmt.Sprintf("FinishWithError: Scanned %d objects. %s %d objects, Error %d objects.\n", scanNum, m.opStr, snap.okNum, snap.errNum))
return getClearStr(fmt.Sprintf("FinishWithError: Scanned %d objects. %s %d objects(skip %d objects), Error %d objects.\n", scanNum, m.opStr, snap.okNum, snap.skipNum, snap.errNum))
}

func (m *Monitor) getDefeatBar() string {
snap := m.getSnapshot()
if m.seekAheadEnd && m.seekAheadError == nil {
return getClearStr(fmt.Sprintf("Total %d objects. %s %d objects, when error happens.\n", m.totalNum, m.opStr, snap.okNum))
return getClearStr(fmt.Sprintf("Total %d objects. %s %d objects(skip %d objects), when error happens.\n", m.totalNum, m.opStr, snap.okNum, snap.skipNum))
}
scanNum := max(m.totalNum, snap.dealNum)
return getClearStr(fmt.Sprintf("Scanned %d objects. %s %d objects, when error happens.\n", scanNum, m.opStr, snap.okNum))
return getClearStr(fmt.Sprintf("Scanned %d objects. %s %d objects(skip %d objects), when error happens.\n", scanNum, m.opStr, snap.okNum, snap.skipNum))
}

// For rm
Expand Down
3 changes: 3 additions & 0 deletions lib/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,9 @@ var OptionMap = map[string]Option{
OptionUserAgent: Option{"", "--ua", "", OptionTypeString, "", "",
"指定http请求中的user agent, 会在缺省值后面加上指定值",
"Specify the user agent in the http request, and the specified value will be added after the default value"},
OptionObjectFile: Option{"", "--object-file", "", OptionTypeString, "", "",
"表示所有待处理的objects,取值为一个存在的文件路径",
"Specify all the objects that need to be operated, and the specified value should be a exists file path"},
}

func (T *Option) getHelp(language string) string {
Expand Down
Loading