Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

daemon: NewDaemon(): replace system.MkdirAll for os.Mkdir where possible #44317

Merged
merged 2 commits into from
Nov 1, 2022
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
20 changes: 10 additions & 10 deletions daemon/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -756,10 +756,8 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S
return nil, fmt.Errorf("Unable to get the full path to the TempDir (%s): %s", tmp, err)
}
if isWindows {
if _, err := os.Stat(realTmp); err != nil && os.IsNotExist(err) {
if err := system.MkdirAll(realTmp, 0700); err != nil {
return nil, fmt.Errorf("Unable to create the TempDir (%s): %s", realTmp, err)
}
if err := system.MkdirAll(realTmp, 0); err != nil {
return nil, fmt.Errorf("Unable to create the TempDir (%s): %s", realTmp, err)
}
Comment on lines +759 to 761
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a follow-up to this PR that makes this go away (but keeping steps "small" for now)

os.Setenv("TEMP", realTmp)
os.Setenv("TMP", realTmp)
Expand Down Expand Up @@ -813,7 +811,7 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S
}

daemonRepo := filepath.Join(config.Root, "containers")
if err := idtools.MkdirAllAndChown(daemonRepo, 0710, idtools.Identity{
if err := idtools.MkdirAllAndChown(daemonRepo, 0o710, idtools.Identity{
UID: idtools.CurrentIdentity().UID,
GID: rootIDs.GID,
}); err != nil {
Expand All @@ -822,16 +820,18 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S

// Create the directory where we'll store the runtime scripts (i.e. in
// order to support runtimeArgs)
daemonRuntimes := filepath.Join(config.Root, "runtimes")
if err := system.MkdirAll(daemonRuntimes, 0700); err != nil {
if err = os.Mkdir(filepath.Join(config.Root, "runtimes"), 0o700); err != nil && !errors.Is(err, os.ErrExist) {
return nil, err
}
if err := d.loadRuntimes(); err != nil {
return nil, err
}

if isWindows {
if err := system.MkdirAll(filepath.Join(config.Root, "credentialspecs"), 0); err != nil {
// Note that permissions (0o700) are ignored on Windows; passing them to
// show intent only. We could consider using idtools.MkdirAndChown here
// to apply an ACL.
if err = os.Mkdir(filepath.Join(config.Root, "credentialspecs"), 0o700); err != nil && !errors.Is(err, os.ErrExist) {
return nil, err
}
}
Expand Down Expand Up @@ -1068,7 +1068,7 @@ func NewDaemon(ctx context.Context, config *config.Config, pluginStore *plugin.S
if err != nil {
return nil, err
}
if err = system.MkdirAll(filepath.Join(config.Root, "trust"), 0700); err != nil {
if err = os.Mkdir(filepath.Join(config.Root, "trust"), 0o700); err != nil && !errors.Is(err, os.ErrExist) {
return nil, err
}
}
Expand Down Expand Up @@ -1345,7 +1345,7 @@ func prepareTempDir(rootDir string) (string, error) {
}
}
}
return tmpDir, idtools.MkdirAllAndChown(tmpDir, 0700, idtools.CurrentIdentity())
return tmpDir, idtools.MkdirAllAndChown(tmpDir, 0o700, idtools.CurrentIdentity())
}

func (daemon *Daemon) setGenericResources(conf *config.Config) error {
Expand Down