resolve a remote by id or partial id

This commit is contained in:
sawka 2022-09-14 13:01:52 -07:00
parent c8b8f78249
commit 83974e10dd
2 changed files with 14 additions and 3 deletions

View File

@ -126,7 +126,7 @@ func resolveRemoteArg(remoteArg string) (*sstore.RemotePtrType, error) {
if rrUser != "" {
return nil, fmt.Errorf("remoteusers not supported")
}
msh := remote.GetRemoteByName(rrRemote)
msh := remote.GetRemoteByArg(rrRemote)
if msh == nil {
return nil, nil
}

View File

@ -10,6 +10,7 @@ import (
"os"
"os/exec"
"path"
"regexp"
"strconv"
"strings"
"sync"
@ -220,12 +221,22 @@ func ArchiveRemote(ctx context.Context, remoteId string) error {
return nil
}
func GetRemoteByName(name string) *MShellProc {
var partialUUIDRe = regexp.MustCompile("^[0-9a-f]{8}$")
func isPartialUUID(s string) bool {
return partialUUIDRe.MatchString(s)
}
func GetRemoteByArg(arg string) *MShellProc {
GlobalStore.Lock.Lock()
defer GlobalStore.Lock.Unlock()
isPuid := isPartialUUID(arg)
for _, msh := range GlobalStore.Map {
rcopy := msh.GetRemoteCopy()
if rcopy.RemoteAlias == name || rcopy.RemoteCanonicalName == name {
if rcopy.RemoteAlias == arg || rcopy.RemoteCanonicalName == arg || rcopy.RemoteId == arg {
return msh
}
if isPuid && strings.HasPrefix(rcopy.RemoteId, arg) {
return msh
}
}