Skip to content

Commit

Permalink
move from shutil to directly chmodding the output file
Browse files Browse the repository at this point in the history
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]>
  • Loading branch information
eli-schwartz committed Nov 3, 2024
1 parent cabd018 commit d998c96
Showing 1 changed file with 2 additions and 5 deletions.
7 changes: 2 additions & 5 deletions pycargoebuild/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import logging
import lzma
import os.path
import shutil
import stat
import subprocess
import sys
import tarfile
Expand Down Expand Up @@ -399,10 +399,7 @@ def repack_crates(tar_out: tarfile.TarFile,
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(),
outf.fileno()) # type: ignore
os.chmod(outf.fileno(), stat.S_IMODE(st.st_mode))
args.input.close()
else:
os.fchmod(outf.fileno(), 0o666 & ~umask)
Expand Down

0 comments on commit d998c96

Please sign in to comment.