getJailFromArray now support long names
This commit is contained in:
parent
1295fb86f6
commit
170dce31b3
46
cmd/utils.go
46
cmd/utils.go
@ -588,13 +588,44 @@ func isStringInArray(strarr []string, searched string) bool {
|
||||
|
||||
/********************************************************************************
|
||||
* Get a specific jail reference, to update properties after a range loop
|
||||
* Name can be short or long form ("myjail" vs "mystore/myjail")
|
||||
*******************************************************************************/
|
||||
func getJailFromArray(name string, jarray []Jail) (*Jail, error) {
|
||||
var ds, jail string
|
||||
var jails []Jail
|
||||
|
||||
if strings.Contains(name, "/") {
|
||||
split := strings.Split(name, "/")
|
||||
if len(split) != 2 {
|
||||
return &Jail{}, errors.New("Invalid format for jail name")
|
||||
}
|
||||
ds = split[0]
|
||||
jail = split[1]
|
||||
} else {
|
||||
jail = name
|
||||
}
|
||||
|
||||
for i, j := range jarray {
|
||||
if name == j.Name {
|
||||
return &jarray[i], nil
|
||||
if jail == j.Name {
|
||||
if len(ds) > 0 {
|
||||
if strings.EqualFold(ds, j.Datastore) {
|
||||
return &jarray[i], nil
|
||||
} else {
|
||||
continue
|
||||
}
|
||||
} else {
|
||||
jails = append(jails, j)
|
||||
}
|
||||
}
|
||||
}
|
||||
if len(jails) > 0 {
|
||||
if len(jails) > 1 {
|
||||
return &Jail{}, errors.New("More than one jail found with this name, please use datastore/jail format")
|
||||
} else {
|
||||
return &jails[0], nil
|
||||
}
|
||||
}
|
||||
|
||||
return &Jail{}, errors.New("Jail not found")
|
||||
}
|
||||
|
||||
@ -637,6 +668,17 @@ func countOfJailsWithThisName(name string) int {
|
||||
return count
|
||||
}
|
||||
|
||||
|
||||
func isNameDistinctive(name string, jails []Jail) bool {
|
||||
_, err := getJailFromArray(name, jails)
|
||||
if err != nil {
|
||||
return false
|
||||
} else {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/********************************************************************************
|
||||
* Recurse into structure, returning reflect.Kind of named field.
|
||||
* Nested fields are named with a dot (ex "MyStruct.MyField")
|
||||
|
Loading…
Reference in New Issue
Block a user