Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Lib/test/test_venv.py
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,27 @@ def test_install_scripts_selinux(self):
venv.create(self.env_dir)
listxattr_mock.assert_not_called()

@unittest.skipIf(os.name == 'nt', 'POSIX-specific permission test')
def test_install_scripts_honors_umask(self):
"""
gh-127172: Activation scripts must inherit the process umask (and any
default ACL) like every other created file, rather than a fixed mode
copied from the source template.
"""
old_umask = os.umask(0o002)
try:
venv.create(self.env_dir, with_pip=False)
bindir = os.path.join(self.env_dir, self.bindir)
control = os.path.join(bindir, 'control')
with open(control, 'w'):
pass
expected = os.stat(control).st_mode & 0o777
for name in ('activate', 'activate.csh', 'activate.fish'):
mode = os.stat(os.path.join(bindir, name)).st_mode & 0o777
self.assertEqual(mode, expected)
finally:
os.umask(old_umask)

def test_overwrite_existing(self):
"""
Test creating environment in an existing directory.
Expand Down
3 changes: 1 addition & 2 deletions Lib/venv/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,11 +592,10 @@ def skip_file(f):
'may be binary: %s', srcfile, e)
continue
if new_data == data:
shutil.copy(srcfile, dstfile)
shutil.copyfile(srcfile, dstfile)
else:
with open(dstfile, 'wb') as f:
f.write(new_data)
shutil.copymode(srcfile, dstfile)

def upgrade_dependencies(self, context):
logger.debug(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Creating a virtual environment with :mod:`venv` now writes the activation
scripts using permissions derived from the process umask (and any default
ACL), consistent with the other files it creates, instead of a fixed mode
copied from the packaged templates. Patch by tonghuaroot.
Loading