mirror of
https://github.com/rclone/rclone.git
synced 2025-12-06 00:03:32 +00:00
refactor: use strings.Cut to simplify code
Signed-off-by: vicerace <vicerace@sohu.com>
This commit is contained in:
@@ -389,8 +389,8 @@ func parseHash(str string) (string, string, error) {
|
||||
if str == "-" {
|
||||
return "", "", nil
|
||||
}
|
||||
if pos := strings.Index(str, ":"); pos > 0 {
|
||||
name, val := str[:pos], str[pos+1:]
|
||||
if before, after, ok := strings.Cut(str, ":"); ok {
|
||||
name, val := before, after
|
||||
if name != "" && val != "" {
|
||||
return name, val, nil
|
||||
}
|
||||
|
||||
@@ -58,10 +58,10 @@ type conn struct {
|
||||
// interoperate with the rclone sftp backend
|
||||
func (c *conn) execCommand(ctx context.Context, out io.Writer, command string) (err error) {
|
||||
binary, args := command, ""
|
||||
space := strings.Index(command, " ")
|
||||
if space >= 0 {
|
||||
binary = command[:space]
|
||||
args = strings.TrimLeft(command[space+1:], " ")
|
||||
before, after, ok := strings.Cut(command, " ")
|
||||
if ok {
|
||||
binary = before
|
||||
args = strings.TrimLeft(after, " ")
|
||||
}
|
||||
args = shellUnEscape(args)
|
||||
fs.Debugf(c.what, "exec command: binary = %q, args = %q", binary, args)
|
||||
|
||||
Reference in New Issue
Block a user