Skip to content

Commit

Permalink
daemon: Daemon.registerName: inline validateID utility
Browse files Browse the repository at this point in the history
This function only checked for the ID to be non-empty, and was only
used in a single location. Also move this check as first check in
registerName, to allow for an early return.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
  • Loading branch information
thaJeztah committed Oct 15, 2024
1 parent 97b1233 commit 71977a8
Showing 1 changed file with 4 additions and 11 deletions.
15 changes: 4 additions & 11 deletions daemon/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@ var (
)

func (daemon *Daemon) registerName(container *container.Container) error {
if daemon.Exists(container.ID) {
return fmt.Errorf("Container is already loaded")
if container.ID == "" {
return fmt.Errorf("invalid empty id")
}
if err := validateID(container.ID); err != nil {
return err
if daemon.Exists(container.ID) {
return fmt.Errorf("container is already loaded")
}
if container.Name == "" {
name, err := daemon.generateAndReserveName(container.ID)
Expand Down Expand Up @@ -106,10 +106,3 @@ func (daemon *Daemon) generateAndReserveName(id string) (string, error) {
}
return name, nil
}

func validateID(id string) error {
if id == "" {
return fmt.Errorf("Invalid empty id")
}
return nil
}

0 comments on commit 71977a8

Please sign in to comment.