Skip to content

Commit

Permalink
Merge 9728-no-zero-umask: Fix some iutils tests on MacOS Catalina
Browse files Browse the repository at this point in the history
Author: glyph
Reviewer: hawkowl
Fixes: ticket:9728
  • Loading branch information
glyph authored and hawkowl committed Nov 12, 2019
1 parent 981dd33 commit 56a8193
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
Empty file.
28 changes: 16 additions & 12 deletions src/twisted/test/test_iutils.py
Expand Up @@ -221,23 +221,27 @@ def _defaultPathTest(self, utilFunc, check):
os.makedirs(dir)

scriptFile = self.makeSourceFile([
"import os, sys, stat",
# Fix the permissions so we can report the working directory.
# On macOS (and maybe elsewhere), os.getcwd() fails with EACCES
# if +x is missing from the working directory.
"os.chmod(%r, stat.S_IXUSR)" % (dir,),
"sys.stdout.write(os.getcwd())"])
"import os, sys",
"cdir = os.getcwd()",
"sys.stdout.write(cdir)"]
)

# Switch to it, but make sure we switch back
self.addCleanup(os.chdir, os.getcwd())
os.chdir(dir)

# Get rid of all its permissions, but make sure they get cleaned up
# later, because otherwise it might be hard to delete the trial
# temporary directory.
self.addCleanup(
os.chmod, dir, stat.S_IMODE(os.stat('.').st_mode))
os.chmod(dir, 0)
# Remember its default permissions.
originalMode = stat.S_IMODE(os.stat('.').st_mode)

# On macOS Catalina (and maybe elsewhere), os.getcwd() sometimes fails
# with EACCES if u+rx is missing from the working directory, so don't
# reduce it further than this.
os.chmod(dir, stat.S_IXUSR | stat.S_IRUSR)

# Restore the permissions to their original state later (probably
# adding at least u+w), because otherwise it might be hard to delete
# the trial temporary directory.
self.addCleanup(os.chmod, dir, originalMode)

# Pass in -S so that if run using the coverage .pth trick, it won't be
# loaded and cause Coverage to try and get the current working
Expand Down

0 comments on commit 56a8193

Please sign in to comment.