0

Add force_writable argument to mirror_dir

Fixes #1611.
This commit is contained in:
Nicolas F
2019-07-12 23:37:35 +02:00
parent 70c64cd4c5
commit a422270666
2 changed files with 11 additions and 5 deletions

View File

@@ -165,14 +165,14 @@ top-level directory.
"overviewer_core", "data", "web_assets") "overviewer_core", "data", "web_assets")
if not os.path.isdir(global_assets): if not os.path.isdir(global_assets):
global_assets = os.path.join(util.get_program_path(), "web_assets") global_assets = os.path.join(util.get_program_path(), "web_assets")
mirror_dir(global_assets, self.outputdir, capabilities=self.fs_caps) mirror_dir(global_assets, self.outputdir, capabilities=self.fs_caps, force_writable=True)
if self.custom_assets_dir: if self.custom_assets_dir:
# We could have done something fancy here rather than just # We could have done something fancy here rather than just
# overwriting the global files, but apparently this what we used to # overwriting the global files, but apparently this what we used to
# do pre-rewrite. # do pre-rewrite.
mirror_dir(self.custom_assets_dir, self.outputdir, mirror_dir(self.custom_assets_dir, self.outputdir, capabilities=self.fs_caps,
capabilities=self.fs_caps) force_writable=True)
# write a dummy baseMarkers.js if none exists # write a dummy baseMarkers.js if none exists
basemarkers_path = os.path.join(self.outputdir, "baseMarkers.js") basemarkers_path = os.path.join(self.outputdir, "baseMarkers.js")

View File

@@ -62,7 +62,7 @@ def does_rename_work(dir_to_test):
return renameworks return renameworks
## useful recursive copy, that ignores common OS cruft ## useful recursive copy, that ignores common OS cruft
def mirror_dir(src, dst, entities=None, capabilities=default_caps): def mirror_dir(src, dst, entities=None, capabilities=default_caps, force_writable=False):
'''copies all of the entities from src to dst''' '''copies all of the entities from src to dst'''
chmod_works = capabilities.get("chmod_works") chmod_works = capabilities.get("chmod_works")
if not os.path.exists(dst): if not os.path.exists(dst):
@@ -80,11 +80,14 @@ def mirror_dir(src, dst, entities=None, capabilities=default_caps):
continue continue
if os.path.isdir(os.path.join(src,entry)): if os.path.isdir(os.path.join(src,entry)):
mirror_dir(os.path.join(src, entry), os.path.join(dst, entry), capabilities=capabilities) mirror_dir(os.path.join(src, entry), os.path.join(dst, entry), capabilities=capabilities, force_writable=force_writable)
elif os.path.isfile(os.path.join(src,entry)): elif os.path.isfile(os.path.join(src,entry)):
try: try:
if chmod_works: if chmod_works:
shutil.copy(os.path.join(src, entry), os.path.join(dst, entry)) shutil.copy(os.path.join(src, entry), os.path.join(dst, entry))
if force_writable: # for shitty neckbeard ware
dst_stat = os.stat(os.path.join(dst, entry))
os.chmod(os.path.join(dst, entry), dst_stat.st_mode | stat.S_IWUSR)
else: else:
shutil.copyfile(os.path.join(src, entry), os.path.join(dst, entry)) shutil.copyfile(os.path.join(src, entry), os.path.join(dst, entry))
except IOError as outer: except IOError as outer:
@@ -99,6 +102,9 @@ def mirror_dir(src, dst, entities=None, capabilities=default_caps):
# try again; if this stills throws an error, let it propagate up # try again; if this stills throws an error, let it propagate up
if chmod_works: if chmod_works:
shutil.copy(os.path.join(src, entry), os.path.join(dst, entry)) shutil.copy(os.path.join(src, entry), os.path.join(dst, entry))
if force_writable:
dst_stat = os.stat(os.path.join(dst, entry))
os.chmod(os.path.join(dst, entry), dst_stat.st_mode | stat.S_IWUSR)
else: else:
shutil.copyfile(os.path.join(src, entry), os.path.join(dst, entry)) shutil.copyfile(os.path.join(src, entry), os.path.join(dst, entry))