Fix daemon EnvVar dirs not being created on startup
This commit is contained in:
parent
c5e919dc86
commit
778db848c6
@ -147,6 +147,10 @@ func NewDaemon(
|
||||
bootstrapFilePath = bootstrap.StateDirPath(d.opts.EnvVars.StateDirPath)
|
||||
)
|
||||
|
||||
if err := d.opts.EnvVars.init(); err != nil {
|
||||
return nil, fmt.Errorf("initializing daemon directories: %w", err)
|
||||
}
|
||||
|
||||
currBootstrap, err := bootstrap.FromFile(bootstrapFilePath)
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
// daemon has never had a network created or joined
|
||||
|
@ -13,17 +13,62 @@ import (
|
||||
"github.com/adrg/xdg"
|
||||
)
|
||||
|
||||
// DEPRECATED
|
||||
//
|
||||
// EnvVars are variables which are derived based on the environment which the
|
||||
// process is running in.
|
||||
//
|
||||
// TODO EnvVars should be private to this package.
|
||||
type EnvVars struct {
|
||||
RuntimeDirPath string
|
||||
StateDirPath string
|
||||
}
|
||||
|
||||
func (e EnvVars) init() error {
|
||||
var errs []error
|
||||
mkDir := func(path string) error {
|
||||
{
|
||||
parentPath := filepath.Dir(path)
|
||||
parentInfo, err := os.Stat(parentPath)
|
||||
if err != nil {
|
||||
return fmt.Errorf("checking parent path %q: %w", parentPath, err)
|
||||
} else if !parentInfo.IsDir() {
|
||||
return fmt.Errorf("%q is not a directory", parentPath)
|
||||
}
|
||||
}
|
||||
|
||||
info, err := os.Stat(path)
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
// fine
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("checking path: %w", err)
|
||||
} else if !info.IsDir() {
|
||||
return fmt.Errorf("path is not a directory")
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := os.Mkdir(path, 0700); err != nil {
|
||||
return fmt.Errorf("creating directory: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := mkDir(e.RuntimeDirPath); err != nil {
|
||||
errs = append(errs, fmt.Errorf(
|
||||
"creating runtime directory %q: %w",
|
||||
e.RuntimeDirPath,
|
||||
err,
|
||||
))
|
||||
}
|
||||
|
||||
if err := mkDir(e.StateDirPath); err != nil {
|
||||
errs = append(errs, fmt.Errorf(
|
||||
"creating state directory %q: %w",
|
||||
e.StateDirPath,
|
||||
err,
|
||||
))
|
||||
}
|
||||
|
||||
return errors.Join(errs...)
|
||||
}
|
||||
|
||||
func getDefaultHTTPSocketDirPath() string {
|
||||
path, err := firstExistingDir(
|
||||
"/run",
|
||||
@ -51,8 +96,6 @@ var HTTPSocketPath = sync.OnceValue(func() string {
|
||||
)
|
||||
})
|
||||
|
||||
// DEPRECATED
|
||||
//
|
||||
// GetEnvVars will return the EnvVars of the current processes, as determined by
|
||||
// the process's environment.
|
||||
var GetEnvVars = sync.OnceValue(func() (v EnvVars) {
|
||||
|
Loading…
Reference in New Issue
Block a user