Skip to content

Commit

Permalink
Merge pull request moby#48669 from thaJeztah/daemon_fix_restore
Browse files Browse the repository at this point in the history
daemon: fix restoring containers with name matching an ID
  • Loading branch information
thaJeztah authored Oct 18, 2024
2 parents 8c5a6c6 + a602054 commit e33fcb4
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions daemon/names.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ 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.containers.Get(container.ID) != nil {
// TODO(thaJeztah): should this be a panic (duplicate IDs due to invalid state on disk?)
// TODO(thaJeztah): should this also check for container.ID being a prefix of another container's ID? (daemon.containersReplica.GetByPrefix); only should happen due to corruption / truncated ID.
return fmt.Errorf("container is already loaded")
}
if container.Name == "" {
name, err := daemon.generateAndReserveName(container.ID)
Expand Down Expand Up @@ -106,10 +108,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 e33fcb4

Please sign in to comment.