Browse Source

Add write permission to read-only files so their domains can be subsituted

This was added because both `third_party/shaka-player/dist/package.json` and
`third_party/shaka-player/dist/shaka-player.ui.extens.js` are read-only when
extracted from the chromium source tarball. Currently, this change could
potentially be replaced by manual vetting and whitelisting of the
beforementioned files from the domain subsitution routine. Another alternative
to this approach would be to pass an argument to tar (or whatever other program
is used to perform the extraction) that specifies that the extracted files are
to be writable.
Zoraver Kang 3 years ago
parent
commit
43fbd1d76c
1 changed files with 5 additions and 0 deletions
  1. 5 0
      utils/domain_substitution.py

+ 5 - 0
utils/domain_substitution.py

@@ -14,6 +14,7 @@ import collections
 import contextlib
 import io
 import os
+import stat
 import re
 import tarfile
 import tempfile
@@ -88,6 +89,10 @@ def _substitute_path(path, regex_iter):
     Raises FileNotFoundError if path does not exist.
     Raises UnicodeDecodeError if path's contents cannot be decoded.
     """
+    if not os.access(path, os.W_OK):
+        # If the patch cannot be written to, it cannot be opened for updating
+        print(str(path) + " cannot be opened for writing! Adding write permission...")
+        path.chmod(path.stat().st_mode | stat.S_IWUSR)
     with path.open('r+b') as input_file:
         original_content = input_file.read()
         if not original_content: