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

Conversation

thaJeztah
Copy link
Member

system.MkdirAll() is a special version of os.Mkdir to handle creating directories
using Windows volume paths ("\\?\Volume{4c1b02c1-d990-11dc-99ae-806e6f6e6963}").
This may be important when MkdirAll is used, which traverses all parent paths to
create them if missing (ultimately landing on the "volume" path).

The daemon.NewDaemon() function used system.MkdirAll() in various places where
a subdirectory within daemon.Root was created. This appeared to be mostly out
of convenience (to not have to handle os.ErrExist errors). The daemon.Root
directory should already be set up in these locations, and should be set up with
correct permissions. Using system.MkdirAll() would potentially mask errors if
the root directory is missing, and instead set up parent directories (possibly
with incorrect permissions).

Because of the above, this patch changes system.MkdirAll to os.Mkdir. As we
are changing these lines, this patch also changes the legacy octal notation
(0700) to the now preferred 0o700.

One location continues to use system.MkdirAll, as the temp-directory may be
configured to be outside of daemon.Root, but a redundant os.Stat(realTmp)
was removed, as system.MkdirAll is expected to handle this.

As we are changing these lines, this patch also changes the legacy octal notation
(0700) to the now preferred 0o700.

`system.MkdirAll()` is a special version of os.Mkdir to handle creating directories
using Windows volume paths (`"\\?\Volume{4c1b02c1-d990-11dc-99ae-806e6f6e6963}"`).
This may be important when `MkdirAll` is used, which traverses all parent paths to
create them if missing (ultimately landing on the "volume" path).

The daemon.NewDaemon() function used `system.MkdirAll()` in various places where
a subdirectory within `daemon.Root` was created. This appeared to be mostly out
of convenience (to not have to handle `os.ErrExist` errors). The `daemon.Root`
directory should already be set up in these locations, and should be set up with
correct permissions. Using `system.MkdirAll()` would potentially mask errors if
the root directory is missing, and instead set up parent directories (possibly
with incorrect permissions).

Because of the above, this patch changes `system.MkdirAll` to `os.Mkdir`. As we
are changing these lines, this patch also changes the legacy octal notation
(`0700`) to the now preferred `0o700`.

One location continues to use `system.MkdirAll`, as the temp-directory may be
configured to be outside of `daemon.Root`, but a redundant `os.Stat(realTmp)`
was removed, as `system.MkdirAll` is expected to handle this.

As we are changing these lines, this patch also changes the legacy octal notation
(`0700`) to the now preferred `0o700`.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Comment on lines +759 to 761
if err := system.MkdirAll(realTmp, 0); err != nil {
return nil, fmt.Errorf("Unable to create the TempDir (%s): %s", realTmp, err)
}
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)

@samuelkarp
Copy link
Member

As we are changing these lines, this patch also changes the legacy octal notation (0700) to the now preferred 0o700.

nit: you've got this text in the commit message twice

@thaJeztah thaJeztah merged commit ef7e4ec into moby:master Nov 1, 2022
@thaJeztah thaJeztah deleted the daemon_mkdir branch November 1, 2022 12:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants