Modified: trunk/Tools/ChangeLog (265122 => 265123)
--- trunk/Tools/ChangeLog 2020-07-31 00:17:53 UTC (rev 265122)
+++ trunk/Tools/ChangeLog 2020-07-31 00:42:41 UTC (rev 265123)
@@ -1,3 +1,22 @@
+2020-07-30 Jonathan Bedard <jbed...@apple.com>
+
+ [webkitcorepy] Make scripts called with sudo use a userspace autoinstall
+ https://bugs.webkit.org/show_bug.cgi?id=214981
+ <rdar://problem/66342996>
+
+ Reviewed by Dewei Zhu.
+
+ Sudo can bring havoc to the autoinstaller, because the directories it creates will belong
+ to the root user. We should ensure that the directories created by a sudo script call
+ are owned by the user that called sudo, when possible.
+
+ * Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py:
+ * Scripts/libraries/webkitcorepy/webkitcorepy/autoinstall.py:
+ (Package.install): Ensure that installed packages are not owned by root, if possible.
+ (AutoInstall.userspace_should_own): Ensure that a directory or file is not owned by root, if possible.
+ (AutoInstall.set_directory): Ensure that the directories containing auto-installed packages are not
+ owned by root, if possible.
+
2020-07-30 Dean Jackson <d...@apple.com>
[WebGL] Safari snapshots of WebGL content in the tab picker don't work
Modified: trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py (265122 => 265123)
--- trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py 2020-07-31 00:17:53 UTC (rev 265122)
+++ trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/__init__.py 2020-07-31 00:42:41 UTC (rev 265123)
@@ -28,7 +28,7 @@
from webkitcorepy.version import Version
from webkitcorepy.string_utils import BytesIO, StringIO, UnicodeIO, unicode
-version = Version(0, 0, 3)
+version = Version(0, 0, 4)
from webkitcorepy.autoinstall import Package, AutoInstall
if sys.version_info > (3, 0):
Modified: trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/autoinstall.py (265122 => 265123)
--- trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/autoinstall.py 2020-07-31 00:17:53 UTC (rev 265122)
+++ trunk/Tools/Scripts/libraries/webkitcorepy/webkitcorepy/autoinstall.py 2020-07-31 00:42:41 UTC (rev 265123)
@@ -182,12 +182,17 @@
os.remove(archive.path)
shutil.rmtree(temp_location, ignore_errors=True)
+ AutoInstall.userspace_should_own(self.location)
+
AutoInstall.manifest[self.name] = {
'index': AutoInstall.index,
'version': str(archive.version),
}
- with open(os.path.join(AutoInstall.directory, 'manifest.json'), 'w') as file:
+
+ manifest = os.path.join(AutoInstall.directory, 'manifest.json')
+ with open(manifest, 'w') as file:
json.dump(AutoInstall.manifest, file)
+ AutoInstall.userspace_should_own(manifest)
log.warning('Installed {}!'.format(archive))
except Exception:
@@ -227,6 +232,30 @@
cls.enabled = False
@classmethod
+ def userspace_should_own(cls, path):
+ # Windows doesn't have sudo
+ if not hasattr(os, "geteuid"):
+ return
+
+ # If we aren't root, the default behavior is correct
+ if os.geteuid() != 0:
+ return
+
+ # If running as sudo, we really want the caller of sudo to own the autoinstall directory
+ uid = int(os.environ.get('SUDO_UID', -1))
+ gid = int(os.environ.get('SUDO_GID', -1))
+
+ os.chown(path, uid, gid)
+ if not os.path.isdir(path):
+ return
+
+ for root, directories, files in os.walk(path):
+ for directory in directories:
+ os.chown(os.path.join(root, directory), uid, gid)
+ for file in files:
+ os.chown(os.path.join(root, file), uid, gid)
+
+ @classmethod
def set_directory(cls, directory):
if not directory or not isinstance(directory, str):
raise ValueError('{} is an invalid autoinstall directory'.format(directory))
@@ -233,10 +262,16 @@
directory = os.path.abspath(directory)
if not os.path.isdir(directory):
+ creation_root = directory
+ while not os.path.isdir(os.path.dirname(creation_root)):
+ creation_root = os.path.dirname(creation_root)
+
if os.path.exists(directory):
raise ValueError('{} is not a directory and cannot be used as the autoinstall location')
os.makedirs(directory)
+ cls.userspace_should_own(creation_root)
+
try:
with open(os.path.join(directory, 'manifest.json'), 'r') as file:
cls.manifest = json.load(file)