mirror of
https://github.com/moby/moby.git
synced 2026-01-11 10:41:43 +00:00
These comments were added to enforce using the correct import path for
our packages ("github.com/docker/docker", not "github.com/moby/moby").
However, when working in go module mode (not GOPATH / vendor), they have
no effect, so their impact is limited.
Remove these imports in preparation of migrating our code to become an
actual go module.
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
37 lines
1.0 KiB
Go
37 lines
1.0 KiB
Go
package daemon
|
|
|
|
import (
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/google/uuid"
|
|
"github.com/moby/sys/atomicwriter"
|
|
"github.com/pkg/errors"
|
|
)
|
|
|
|
const idFilename = "engine-id"
|
|
|
|
// LoadOrCreateID loads the engine's ID from the given root, or generates a new ID
|
|
// if it doesn't exist. It returns the ID, and any error that occurred when
|
|
// saving the file.
|
|
//
|
|
// Note that this function expects the daemon's root directory to already have
|
|
// been created with the right permissions and ownership (usually this would
|
|
// be done by daemon.CreateDaemonRoot().
|
|
func LoadOrCreateID(root string) (string, error) {
|
|
var id string
|
|
idPath := filepath.Join(root, idFilename)
|
|
idb, err := os.ReadFile(idPath)
|
|
if os.IsNotExist(err) {
|
|
id = uuid.New().String()
|
|
if err := atomicwriter.WriteFile(idPath, []byte(id), os.FileMode(0o600)); err != nil {
|
|
return "", errors.Wrap(err, "error saving ID file")
|
|
}
|
|
} else if err != nil {
|
|
return "", errors.Wrapf(err, "error loading ID file %s", idPath)
|
|
} else {
|
|
id = string(idb)
|
|
}
|
|
return id, nil
|
|
}
|