Skip to content

user: mkdirAs: refactor and touch-up comments for clarity - #238

Open
thaJeztah wants to merge 1 commit into
moby:mainfrom
thaJeztah:refactor_mkdirAs
Open

thaJeztah wants to merge 1 commit into
moby:mainfrom
thaJeztah:refactor_mkdirAs

Conversation

@thaJeztah

@thaJeztah thaJeztah commented Jul 23, 2026 •

Copy link
Copy Markdown
Member

Simplify the implementation by using scoped error variables and a more concise loop for collecting missing parent directories.

Rename variables and clarify comments to make it easier to follow which directories receive ownership and permission changes.

Copilot AI review requested due to automatic review settings July 23, 2026 11:00

This comment was marked as off-topic.

Simplify the implementation by using scoped error variables and a
more concise loop for collecting missing parent directories.

Rename variables and clarify comments to make it easier to follow
which directories receive ownership and permission changes.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
@thaJeztah
thaJeztah marked this pull request as ready for review October 27, 2026 10:35
Comment thread user/idtools_unix.go
// Track the requested directory and any parent directories created by
// Mkdir/MkdirAll to set their ownership and permissions afterward.
var createdDirs []string
if os.IsNotExist(statErr) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

nit: maybe switch to errors.Is while at it.

Comment thread user/idtools_unix.go
Comment on lines +47 to +49
for p := filepath.Dir(path); p != "/"; p = filepath.Dir(p) {
if _, err := os.Stat(p); os.IsNotExist(err) {
createdDirs = append(createdDirs, p)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I know this is a pre-existing issue, but the logic here is sub-optimal. If a directory exists, there's no need to check its parent, we can break right away.

More to say, we already know if path exists or not, so we can easily skip the whole if mkAll {}.

If you're going to implement it, please do so in a separate commit )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants