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

Preserve file ownership when rewriting input ebuild #32

Closed
wants to merge 2 commits into from

Conversation

eli-schwartz
Copy link
Contributor

If sudo pycargoebuild is used, e.g. to store downloaded crates in /var/cache/distfiles, the ebuild file ends up chowned to root since it is atomically rewritten. Explicitly chown it back.

@@ -397,6 +397,8 @@ def repack_crates(tar_out: tarfile.TarFile,
delete=False) as outf:
try:
if args.input is not None:
st = os.stat(args.input.fileno())
os.chown(outf.fileno(), st.st_uid, st.st_gid)
# typeshed is missing fd support in shutil.copymode()
# https://github.com/python/typeshed/issues/9288
shutil.copymode(args.input.fileno(),
Copy link
Member

Choose a reason for hiding this comment

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

Since you're doing a stat() now, let's replace this with os.chmod() as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. This lets us totally get rid of the shutil import, too...

If `sudo pycargoebuild` is used, e.g. to store downloaded crates in
/var/cache/distfiles, the ebuild file ends up chowned to root since it
is atomically rewritten. Explicitly chown it back.

Signed-off-by: Eli Schwartz <[email protected]>
After the previous commit, this is our only use of shutil, which
provides a "portable wrapper for chmod" (assuming we needed Windows
support) and doesn't actually have type safety since typeshed
doesn't accept the use of file descriptors since it isn't documented and
won't work with follow_symlinks=False... that we don't use.

The regular os functions are simpler and type-safe, so let's just use
it.

Signed-off-by: Eli Schwartz <[email protected]>
Copy link
Member

@mgorny mgorny left a comment

Choose a reason for hiding this comment

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

Thanks!

@mgorny mgorny closed this in 324063e Nov 3, 2024
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.

2 participants