Skip to content

Remove uses of deprecated MkdirAllAs(), MkdirAs()#35541

Merged
AkihiroSuda merged 3 commits intomoby:masterfrom
thaJeztah:remove-deprecated-mkdirallas
Nov 22, 2017
Merged

Remove uses of deprecated MkdirAllAs(), MkdirAs()#35541
AkihiroSuda merged 3 commits intomoby:masterfrom
thaJeztah:remove-deprecated-mkdirallas

Conversation

@thaJeztah
Copy link
Copy Markdown
Member

  • Removes uses of deprecated idtools.MkdirAllAs(), idtools.MkdirAs()
  • Minor refactor of the idtools package

ping @dnephin PTAL

Comment thread daemon/graphdriver/overlay/overlay.go Outdated
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.

Looks like this line is not needed at al if the MkdirAllAndChown() above doesn't use path.Dir(dir), but perhaps I misunderstood the logic, and it's there for a specific reason

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

(copy/paste from slack for everyone reading this)

This seems correct to me. First call basically ensures that /var/lib/docker/overlay/ exists and is a directory (and it needs to do it recursively this is why it's MkdirAll). Second call just creates directory under it and there's no need for recursion. Surely these two can be combined, maybe the reason was clearer error diagnostics in case something is wrong. Maybe there's something else I'm missing here, but I'd leave it as is, no point in optimization.

Comment thread daemon/graphdriver/overlay2/overlay.go Outdated
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.

Same here

Comment thread pkg/idtools/idtools_unix.go Outdated
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.

This is new; previously any error that was not an os.IsNotExist() was ignored; I think this is correct, but double check if there was a reason we ignored those errors

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would guess it is because the Stat is not really important. It's just a check to see if the operation can be skipped, a failure is acceptable here. If the path is invalid then the mkdir() below will error out with a more appropriate error message.

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.

Ah, yes, you may be right; returning this error won't add much. Let me revert this part

@thaJeztah
Copy link
Copy Markdown
Member Author

MkdirAs() and MkdirAllAs() are now no longer used, so perhaps it's ok to remove them (but didn't do that yet, because it's a pkg, so could be used elsewhere

Copy link
Copy Markdown
Member

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

I think it's fine to remove the old deprecated functions

Comment thread pkg/idtools/idtools_unix.go Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would guess it is because the Stat is not really important. It's just a check to see if the operation can be skipped, a failure is acceptable here. If the path is invalid then the mkdir() below will error out with a more appropriate error message.

Comment thread daemon/graphdriver/lcow/lcow.go Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

small nitpick (optional): declaring and assigning zeroIDPair = idtools.IDPair{UID: 0, GID: 0} and passing it in all the MkdirAllAndChown.

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.

I initially started doing that, but decided that it was only used in three locations here, and found this more readable (without having to look what zeroIDPair actually was).

For the other locations; I was thinking of adding a idtools.GetRootIDPair(d.uidMaps, d.gidMaps) utility, but kept that for a possible follow-up

Copy link
Copy Markdown
Contributor

@boaz0 boaz0 left a comment

Choose a reason for hiding this comment

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

LGTM

@thaJeztah thaJeztah force-pushed the remove-deprecated-mkdirallas branch from b04086d to b725e0e Compare November 21, 2017 12:50
Copy link
Copy Markdown
Member Author

@thaJeztah thaJeztah left a comment

Choose a reason for hiding this comment

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

@dnephin @ripcurld0 updated: PTAL

Signed-off-by: Sebastiaan van Stijn <[email protected]>
@thaJeztah thaJeztah force-pushed the remove-deprecated-mkdirallas branch from b725e0e to 38b3af5 Compare November 21, 2017 12:54
Copy link
Copy Markdown
Contributor

@boaz0 boaz0 left a comment

Choose a reason for hiding this comment

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

still LGTM

Copy link
Copy Markdown
Member

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

LGTM

// if it already exists
// If not populate the dir structure
if err := idtools.MkdirAllAs(root, 0700, rootUID, rootGID); err != nil {
if err := idtools.MkdirAllAndChown(root, 0700, idtools.IDPair{UID: rootUID, GID: rootGID}); err != nil {
Copy link
Copy Markdown
Contributor

@kolyshkin kolyshkin Nov 21, 2017

Choose a reason for hiding this comment

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

Perhaps for the sake of readability/simplicity it makes sense to do something like

owner :=  idtools.IDPair{UID: rootUID, GID: rootGID}

and then use it

if err := idtools.MkdirAllAndChown(root, 0700, owner); err != nil {

otherwise it looks like excessive typing or autogenerated code (which might actually be true -- I bet @thaJeztah used good ol' sed or other form of find/replace 👍 )

Same for all similar places.

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.

See my earlier comment; re: using a variable or not #35541 (comment)

@AkihiroSuda AkihiroSuda merged commit 84b1f81 into moby:master Nov 22, 2017
@thaJeztah thaJeztah deleted the remove-deprecated-mkdirallas branch November 22, 2017 08:54
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.

7 participants