mirror of
https://github.com/lxc/incus
synced 2026-08-02 05:26:46 +00:00
global: Use strings.Cut instead of strings.Split/SplitN
Signed-off-by: Stéphane Graber <stgraber@stgraber.org>
This commit is contained in:
parent
99e0d89fe1
commit
b7a3c767f8
@ -62,7 +62,7 @@ func NewStmt(localPath string, parsedPkgs []*packages.Package, entity, kind stri
|
||||
|
||||
// Generate plumbing and wiring code for the desired statement.
|
||||
func (s *Stmt) Generate(buf *file.Buffer) error {
|
||||
kind := strings.Split(s.kind, "-by-")[0]
|
||||
kind, _, _ := strings.Cut(s.kind, "-by-")
|
||||
|
||||
switch kind {
|
||||
case "objects":
|
||||
|
||||
@ -391,7 +391,7 @@ func (g *cmdGlobal) cmpInstancesAndSnapshots(toComplete string) ([]string, cobra
|
||||
resource := resources[0]
|
||||
|
||||
if strings.Contains(resource.name, instance.SnapshotDelimiter) {
|
||||
instName := strings.SplitN(resource.name, instance.SnapshotDelimiter, 2)[0]
|
||||
instName, _, _ := strings.Cut(resource.name, instance.SnapshotDelimiter)
|
||||
snapshots, _ := resource.server.GetInstanceSnapshotNames(instName)
|
||||
for _, snapshot := range snapshots {
|
||||
results = append(results, fmt.Sprintf("%s/%s", instName, snapshot))
|
||||
@ -1123,7 +1123,7 @@ func (g *cmdGlobal) cmpStoragePoolWithVolume(toComplete string) ([]string, cobra
|
||||
return results, cobra.ShellCompDirectiveNoSpace
|
||||
}
|
||||
|
||||
pool := strings.Split(toComplete, "/")[0]
|
||||
pool, _, _ := strings.Cut(toComplete, "/")
|
||||
volumes, compdir := g.cmpStoragePoolVolumes(pool)
|
||||
if compdir == cobra.ShellCompDirectiveError {
|
||||
return nil, compdir
|
||||
|
||||
@ -1043,7 +1043,7 @@ func (c *cmdProjectInfo) run(cmd *cobra.Command, args []string) error {
|
||||
byteLimits := []string{"disk", "memory"}
|
||||
data := [][]string{}
|
||||
for k, v := range projectState.Resources {
|
||||
shortKey := strings.SplitN(k, ".", 2)[0]
|
||||
shortKey, _, _ := strings.Cut(k, ".")
|
||||
|
||||
limit := i18n.G("UNLIMITED")
|
||||
if v.Limit >= 0 {
|
||||
|
||||
@ -2633,7 +2633,7 @@ func pruneLeftoverImages(s *state.State) {
|
||||
|
||||
// Check and delete leftovers
|
||||
for _, entry := range entries {
|
||||
fp := strings.Split(entry.Name(), ".")[0]
|
||||
fp, _, _ := strings.Cut(entry.Name(), ".")
|
||||
if !slices.Contains(images, fp) {
|
||||
err = os.RemoveAll(internalUtil.VarPath("images", entry.Name()))
|
||||
if err != nil {
|
||||
|
||||
@ -152,7 +152,7 @@ func storagePoolVolumeBackupLoadByName(ctx context.Context, s *state.State, proj
|
||||
return nil, err
|
||||
}
|
||||
|
||||
volumeName := strings.Split(backupName, "/")[0]
|
||||
volumeName, _, _ := strings.Cut(backupName, "/")
|
||||
volBackup := backup.NewVolumeBackup(s, projectName, poolName, volumeName, b.ID, b.Name, b.CreationDate, b.ExpiryDate, b.VolumeOnly, b.OptimizedStorage)
|
||||
|
||||
return volBackup, nil
|
||||
|
||||
@ -3039,7 +3039,7 @@ func (d *disk) getParentBlocks(path string) ([]string, error) {
|
||||
|
||||
if fsName == "zfs" && util.PathExists("/dev/zfs") {
|
||||
// Accessible zfs filesystems
|
||||
poolName := strings.Split(dev[1], "/")[0]
|
||||
poolName, _, _ := strings.Cut(dev[1], "/")
|
||||
|
||||
output, err := subprocess.RunCommand("zpool", "status", "-P", "-L", poolName)
|
||||
if err != nil {
|
||||
|
||||
@ -312,7 +312,7 @@ func (d *qemu) memoryTopology(bs *qemuBootState) (*qemuMemoryTopology, error) {
|
||||
}
|
||||
}
|
||||
|
||||
cpuType := strings.Split(bs.CPUType, ",")[0]
|
||||
cpuType, _, _ := strings.Cut(bs.CPUType, ",")
|
||||
if (cpuType == "host" || cpuType == "kvm64") && memoryHotplugEnabled {
|
||||
if !util.IsTrueOrEmpty(limitsMemoryHotplug) {
|
||||
maxMemoryBytes, err = units.ParseByteSizeString(limitsMemoryHotplug)
|
||||
|
||||
@ -350,7 +350,7 @@ func (d *lvm) createDefaultThinPool(lvmVersion, thinPoolName string, thinpoolSiz
|
||||
|
||||
// lvmVersionIsAtLeast checks whether the installed version of LVM is at least the specific version.
|
||||
func (d *lvm) lvmVersionIsAtLeast(sTypeVersion string, versionString string) (bool, error) {
|
||||
lvmVersionString := strings.Split(sTypeVersion, "/")[0]
|
||||
lvmVersionString, _, _ := strings.Cut(sTypeVersion, "/")
|
||||
|
||||
lvmVersion, err := version.Parse(lvmVersionString)
|
||||
if err != nil {
|
||||
|
||||
@ -198,7 +198,7 @@ func (d *truenas) getCachedProperty(dataset string, key string) (string, bool) {
|
||||
}
|
||||
|
||||
// Update cache if needed.
|
||||
parentDataset := strings.Split(dataset, "@")[0]
|
||||
parentDataset, _, _ := strings.Cut(dataset, "@")
|
||||
d.prefillCachedProperties(parentDataset)
|
||||
|
||||
// Get the value.
|
||||
|
||||
@ -640,7 +640,7 @@ func (d *zfs) importPool() (bool, error) {
|
||||
}
|
||||
|
||||
// Check if the pool exists.
|
||||
poolName := strings.Split(d.config["zfs.pool_name"], "/")[0]
|
||||
poolName, _, _ := strings.Cut(d.config["zfs.pool_name"], "/")
|
||||
exists, err = d.datasetExists(poolName)
|
||||
if err != nil {
|
||||
return false, err
|
||||
@ -732,7 +732,7 @@ func (d *zfs) Unmount() (bool, error) {
|
||||
}
|
||||
|
||||
// Export the pool.
|
||||
poolName := strings.Split(d.config["zfs.pool_name"], "/")[0]
|
||||
poolName, _, _ := strings.Cut(d.config["zfs.pool_name"], "/")
|
||||
_, err = subprocess.RunCommand("zpool", "export", poolName)
|
||||
if err != nil {
|
||||
return false, err
|
||||
|
||||
@ -177,7 +177,7 @@ func (d *zfs) getCachedProperty(dataset string, key string) (string, bool) {
|
||||
}
|
||||
|
||||
// Update cache if needed.
|
||||
parentDataset := strings.Split(dataset, "@")[0]
|
||||
parentDataset, _, _ := strings.Cut(dataset, "@")
|
||||
d.prefillCachedProperties(parentDataset)
|
||||
|
||||
// Get the value.
|
||||
|
||||
@ -80,8 +80,8 @@ func (a ByNameAndType) Swap(i, j int) {
|
||||
|
||||
func (a ByNameAndType) Less(i, j int) bool {
|
||||
// Sort snapshot and parent together.
|
||||
iType := strings.Split(a[i][0], " ")[0]
|
||||
jType := strings.Split(a[j][0], " ")[0]
|
||||
iType, _, _ := strings.Cut(a[i][0], " ")
|
||||
jType, _, _ := strings.Cut(a[j][0], " ")
|
||||
|
||||
if iType != jType {
|
||||
return sortorder.NaturalLess(a[i][0], a[j][0])
|
||||
|
||||
@ -36,7 +36,7 @@ type userStore struct {
|
||||
}
|
||||
|
||||
func NewUserStore(issuer string) UserStore {
|
||||
hostname := strings.Split(strings.Split(issuer, "://")[1], ":")[0]
|
||||
hostname, _, _ := strings.Cut(strings.Split(issuer, "://")[1], ":")
|
||||
return userStore{
|
||||
users: map[string]*User{
|
||||
"id1": {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user