Skip to content

Respect tar entries modes when rewriting them on Windows#32959

Merged
tonistiigi merged 1 commit intomoby:masterfrom
simonferquel:tar-filemode-windows
May 16, 2017
Merged

Respect tar entries modes when rewriting them on Windows#32959
tonistiigi merged 1 commit intomoby:masterfrom
simonferquel:tar-filemode-windows

Conversation

@simonferquel
Copy link
Contributor

Previously, only perm-related bits where preserved when rewriting
FileMode in tar entries on Windows. This had the nasty side effect of
having tarsum returning different values when executing from a tar filed
produced on Windows or Linux.

This fix the issue, and pave the way for incremental build context
to work in hybrid contexts.

Signed-off-by: Simon Ferquel [email protected]

- What I did

Modified the chmodTarEntry function on Windows, to copy without any modification bits not related with file permissions

- How I did it

Combination of bitmasks

- How to verify it

Unit tests are included:

  • modified TestChmodTarEntry to add cases where the dir flag / symlink flags are present and should be present in the result
  • modified tarsum related tests to make sure Windows computes the same tarsums than on Linux (I made sure to create everything with 755 permissions, so that the chmodTarEntry windows implementation has no effect and should produce the exact same tarentry than on Linux.

- Description for the changelog

Fixed an issue in tar packaging on Windows where some entries did not have the correct flags

- A picture of a cute animal (not mandatory but encouraged)
Image of ninjacat

Previously, only perm-related bits where preserved when rewriting
FileMode in tar entries on Windows. This had the nasty side effect of
having tarsum returning different values when executing from a tar filed
produced on Windows or Linux.

This fix the issue, and pave the way for incremental build context
to work in hybrid contexts.

Signed-off-by: Simon Ferquel <[email protected]>
@simonferquel
Copy link
Contributor Author

@tonistiigi I'm not sure if it could have some nasty side effects (like invalidating existing images SHA etc.). could you PTAL ?

Copy link
Member

@tonistiigi tonistiigi left a comment

Choose a reason for hiding this comment

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

LGTM

This should not affect existing images. Headers for them are already stored in tar-split files. It will break build cache for windows but that should be ok.

@dmcgowan

func chmodTarEntry(perm os.FileMode) os.FileMode {
perm &= 0755
//perm &= 0755 // this 0-ed out tar flags (like link, regular file, directory marker etc.)
permPart := perm & os.ModePerm
Copy link
Member

Choose a reason for hiding this comment

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

nit: why & os.ModePerm here

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is for readability: make it very explicits that the bits are splitted between a permission block, and the other bits.
As os.ModePerm and the other litterals used in bitwise computations here are compile-time constant, I assume all of this will be optimized away, and opted for clarity.

@thaJeztah
Copy link
Member

ping @jhowardmsft @johnstep PTAL

@lowenna
Copy link
Member

lowenna commented May 15, 2017

@jstarks PTAL.

The change looks reasonable, but I'm concerned it breaks builder caches. As Tonis said, that's probably OK.

@jstarks
Copy link
Contributor

jstarks commented May 15, 2017

LGTM

Copy link
Member

@lowenna lowenna left a comment

Choose a reason for hiding this comment

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

LGTM

@tonistiigi tonistiigi merged commit ad846a1 into moby:master May 16, 2017
@GordonTheTurtle GordonTheTurtle added this to the 17.06.0 milestone May 16, 2017
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