Skip to content

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

Merged
thaJeztah merged 2 commits into
moby:mainfrom
thaJeztah:refactor_mkdirAs
Nov 24, 2026
Merged

thaJeztah merged 2 commits 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.

@thaJeztah
thaJeztah force-pushed the refactor_mkdirAs branch 2 times, most recently from b67c637 to 895a1b1 Compare October 27, 2026 10:34
@thaJeztah
thaJeztah marked this pull request as ready for review October 27, 2026 10:35
Comment thread user/idtools_unix.go Resolved
Comment thread user/idtools_unix.go Outdated
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 )

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Updated this to break early.

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 <[email protected]>
Stop walking parent directories when an existing directory is found,
as its ancestors must already exist.

Also skip collecting missing parent directories when the initial Stat
did not return os.ErrNotExist.

Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah

Copy link
Copy Markdown
Member Author

I'll bring this one in. There's probably more cleaning up to do as follow-ups

@thaJeztah
thaJeztah merged commit f93074f into moby:main Nov 24, 2026
25 checks passed
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.

4 participants