mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
f8453cd049
Remove logging for now because it is complicating things Docker-DCO-1.1-Signed-off-by: Michael Crosby <michael@crosbymichael.com> (github: crosbymichael)
28 lines
744 B
Go
28 lines
744 B
Go
package utils
|
|
|
|
import (
|
|
"crypto/rand"
|
|
"encoding/hex"
|
|
"io"
|
|
"path/filepath"
|
|
)
|
|
|
|
// GenerateRandomName returns a new name joined with a prefix. This size
|
|
// specified is used to truncate the randomly generated value
|
|
func GenerateRandomName(prefix string, size int) (string, error) {
|
|
id := make([]byte, 32)
|
|
if _, err := io.ReadFull(rand.Reader, id); err != nil {
|
|
return "", err
|
|
}
|
|
return prefix + hex.EncodeToString(id)[:size], nil
|
|
}
|
|
|
|
// ResolveRootfs ensures that the current working directory is
|
|
// not a symlink and returns the absolute path to the rootfs
|
|
func ResolveRootfs(uncleanRootfs string) (string, error) {
|
|
rootfs, err := filepath.Abs(uncleanRootfs)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
return filepath.EvalSymlinks(rootfs)
|
|
}
|