diff options
author | Takeshi KOMIYA <i.tkomiya@gmail.com> | 2021-02-05 16:48:29 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-05 16:48:29 +0300 |
commit | ed2af230e435b516bebbeed413f8484ae6ddfbdf (patch) | |
tree | bda1fdff6ddb2a72bd138c94699361423a6450b3 /sphinx/testing | |
parent | 50b0cec41cb2eeccb95c1f7d4b5b40a55dcb408b (diff) | |
parent | 1fc7bc6b1e0790532f13a9c17bea9e0aec00b79c (diff) |
Merge pull request #8823 from tk0miya/8511_readonly_testing
Support testing from read-only filesystems
Diffstat (limited to 'sphinx/testing')
-rw-r--r-- | sphinx/testing/path.py | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/sphinx/testing/path.py b/sphinx/testing/path.py index efc5e8f63..e8509d5ba 100644 --- a/sphinx/testing/path.py +++ b/sphinx/testing/path.py @@ -18,6 +18,17 @@ from sphinx.deprecation import RemovedInSphinx50Warning FILESYSTEMENCODING = sys.getfilesystemencoding() or sys.getdefaultencoding() +def getumask() -> int: + """Get current umask value""" + umask = os.umask(0) # Note: Change umask value temporarily to obtain it + os.umask(umask) + + return umask + + +UMASK = getumask() + + class path(str): """ Represents a path which behaves like a string. @@ -98,6 +109,16 @@ class path(str): pointed to by the symbolic links are copied. """ shutil.copytree(self, destination, symlinks=symlinks) + if os.environ.get('SPHINX_READONLY_TESTDIR'): + # If source tree is marked read-only (e.g. because it is on a read-only + # filesystem), `shutil.copytree` will mark the destination as read-only + # as well. To avoid failures when adding additional files/directories + # to the destination tree, ensure destination directories are not marked + # read-only. + for root, dirs, files in os.walk(destination): + os.chmod(root, 0o755 & ~UMASK) + for name in files: + os.chmod(os.path.join(root, name), 0o644 & ~UMASK) def movetree(self, destination: str) -> None: """ |