Skip to content

Rename vars using builtin names #2006

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Apr 28, 2025
Merged
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
14 changes: 7 additions & 7 deletions client/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,22 +164,22 @@ type remoteOperationResult struct {
Error error
}

func remoteOperationError(msg string, errors []remoteOperationResult) error {
func remoteOperationError(msg string, errorOperationResults []remoteOperationResult) error {
// Check if empty
if len(errors) == 0 {
if len(errorOperationResults) == 0 {
return nil
}

// Check if all identical
var err error
for _, entry := range errors {
for _, entry := range errorOperationResults {
if err != nil && entry.Error.Error() != err.Error() {
errorStrs := make([]string, 0, len(errors))
for _, error := range errors {
errorStrs = append(errorStrs, fmt.Sprintf("%s: %v", error.URL, error.Error))
errorStrings := make([]string, 0, len(errorOperationResults))
for _, operationResult := range errorOperationResults {
errorStrings = append(errorStrings, fmt.Sprintf("%s: %v", operationResult.URL, operationResult.Error))
}

return fmt.Errorf("%s:\n - %s", msg, strings.Join(errorStrs, "\n - "))
return fmt.Errorf("%s:\n - %s", msg, strings.Join(errorStrings, "\n - "))
}

err = entry.Error
Expand Down
4 changes: 2 additions & 2 deletions cmd/incusd/devices.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ func fillFixedInstances(fixedInstances map[int64][]instance.Instance, inst insta
//
// Overall, this function ensures that the CPU resources of the host are utilized effectively amongst all the containers running on it.
func deviceTaskBalance(s *state.State) {
min := func(x, y int) int {
minFunc := func(x, y int) int {
if x < y {
return x
}
Expand Down Expand Up @@ -510,7 +510,7 @@ func deviceTaskBalance(s *state.State) {
count, err := strconv.Atoi(cpulimit)
if err == nil {
// Load-balance
count = min(count, len(cpus))
count = minFunc(count, len(cpus))
if len(numaCpus) > 0 {
fillFixedInstances(fixedInstances, c, cpus, numaCpus, count, true)
} else {
Expand Down
4 changes: 2 additions & 2 deletions cmd/incusd/main_cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ func (c *cmdCluster) Command() *cobra.Command {
cmd.AddCommand(listDatabase.Command())

// Recover
recover := cmdClusterRecoverFromQuorumLoss{global: c.global}
cmd.AddCommand(recover.Command())
recoverFromQuorumLoss := cmdClusterRecoverFromQuorumLoss{global: c.global}
cmd.AddCommand(recoverFromQuorumLoss.Command())

// Remove a raft node.
removeRaftNode := cmdClusterRemoveRaftNode{global: c.global}
Expand Down
6 changes: 3 additions & 3 deletions internal/server/config/safe.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ func SafeLoad(schema Schema, values map[string]string) (Map, error) {
return m, err
}

for _, error := range errors {
message := fmt.Sprintf("Invalid configuration key: %s", error.Reason)
logger.Error(message, logger.Ctx{"key": error.Name})
for _, e := range errors {
message := fmt.Sprintf("Invalid configuration key: %s", e.Reason)
logger.Error(message, logger.Ctx{"key": e.Name})
}
}

Expand Down
28 changes: 16 additions & 12 deletions internal/server/events/connections.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,21 +52,25 @@ func NewWebsocketListenerConnection(connection *websocket.Conn) EventListenerCon
}

func (e *websockListenerConnection) Reader(ctx context.Context, recvFunc EventHandler) {
ctx, cancel := context.WithCancel(ctx)
ctx, cancelFunc := context.WithCancel(ctx)

close := func() {
closeFunc := func() {
e.lock.Lock()
defer e.lock.Unlock()

if ctx.Err() != nil {
return
}

_ = e.Close()
cancel()
err := e.Close()
if err != nil {
logger.Warn("Failed closing connection", logger.Ctx{"err": err})
}

cancelFunc()
}

defer close()
defer closeFunc()

pingInterval := time.Second * 10
e.pongsPending = 0
Expand All @@ -80,7 +84,7 @@ func (e *websockListenerConnection) Reader(ctx context.Context, recvFunc EventHa

// Start reader from client.
go func() {
defer close()
defer closeFunc()

if recvFunc != nil {
for {
Expand Down Expand Up @@ -170,7 +174,7 @@ X-Content-Type-Options: nosniff
func (e *streamListenerConnection) Reader(ctx context.Context, recvFunc EventHandler) {
ctx, cancelFunc := context.WithCancel(ctx)

close := func() {
closeFunc := func() {
e.lock.Lock()
defer e.lock.Unlock()

Expand All @@ -186,11 +190,11 @@ func (e *streamListenerConnection) Reader(ctx context.Context, recvFunc EventHan
cancelFunc()
}

defer close()
defer closeFunc()

// Start reader from client.
go func() {
defer close()
defer closeFunc()

buf := make([]byte, 1)

Expand Down Expand Up @@ -239,7 +243,7 @@ func NewSimpleListenerConnection(rwc io.ReadWriteCloser) EventListenerConnection
func (e *simpleListenerConnection) Reader(ctx context.Context, recvFunc EventHandler) {
ctx, cancelFunc := context.WithCancel(ctx)

close := func() {
closeFunc := func() {
e.lock.Lock()
defer e.lock.Unlock()

Expand All @@ -255,11 +259,11 @@ func (e *simpleListenerConnection) Reader(ctx context.Context, recvFunc EventHan
cancelFunc()
}

defer close()
defer closeFunc()

// Start reader from client.
go func() {
defer close()
defer closeFunc()

buf := make([]byte, 1)

Expand Down
16 changes: 8 additions & 8 deletions internal/server/instance/drivers/driver_qemu_templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -529,17 +529,17 @@ func qemuCPU(opts *qemuCPUOpts, pinning bool) []cfg.Section {
}

// Cap the max number of CPUs to 64 unless directly assigned more.
max := 64
if int(cpu.Total) < max {
max = int(cpu.Total)
} else if opts.cpuRequested > max {
max = opts.cpuRequested
} else if opts.cpuCount > max {
max = opts.cpuCount
maxCpus := 64
if int(cpu.Total) < maxCpus {
maxCpus = int(cpu.Total)
} else if opts.cpuRequested > maxCpus {
maxCpus = opts.cpuRequested
} else if opts.cpuCount > maxCpus {
maxCpus = opts.cpuCount
}

entries = append(entries, cfg.Entry{
Key: "maxcpus", Value: fmt.Sprintf("%d", max),
Key: "maxcpus", Value: fmt.Sprintf("%d", maxCpus),
})
}

Expand Down
6 changes: 3 additions & 3 deletions internal/server/network/network_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1334,14 +1334,14 @@ func ParseIPCIDRToNet(ipAddressCIDR string) (*net.IPNet, error) {

// IPToNet converts an IP to a single host IPNet.
func IPToNet(ip net.IP) net.IPNet {
len := 32
bits := 32
if ip.To4() == nil {
len = 128
bits = 128
}

return net.IPNet{
IP: ip,
Mask: net.CIDRMask(len, len),
Mask: net.CIDRMask(bits, bits),
}
}

Expand Down
8 changes: 4 additions & 4 deletions internal/version/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ func NewDottedVersion(versionString string) (*DottedVersion, error) {
return nil, formatError
}

maj, err := strconv.Atoi(split[0])
major, err := strconv.Atoi(split[0])
if err != nil {
return nil, formatError
}

min, err := strconv.Atoi(split[1])
minor, err := strconv.Atoi(split[1])
if err != nil {
return nil, formatError
}
Expand All @@ -41,8 +41,8 @@ func NewDottedVersion(versionString string) (*DottedVersion, error) {
}

return &DottedVersion{
Major: maj,
Minor: min,
Major: major,
Minor: minor,
Patch: patch,
}, nil
}
Expand Down