From 0bf932935b912f5a4b594182b347f4698a0052dc Mon Sep 17 00:00:00 2001 From: amesgen Date: Mon, 27 Jun 2022 21:22:24 +0200 Subject: [PATCH] Make theme dir writable after copying to it In certain settings (i.e. when using the nix package manager), program files are stored as read-only. Hence, copying the themes from there will result in read-only directories in the output directory, making subsequent operations fail due to permission errors. There does not seem to be a way to let `shutil.copytree` "forget" permissions, so we adapt them after the fact. --- sigal/writer.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/sigal/writer.py b/sigal/writer.py index c7125df..97a0a38 100644 --- a/sigal/writer.py +++ b/sigal/writer.py @@ -24,6 +24,7 @@ import importlib import logging import os import shutil +import stat import sys import types @@ -105,6 +106,15 @@ class AbstractWriter: ): shutil.copytree(static_path, self.theme_path, dirs_exist_ok=True) + # Ensure that the theme dir is writeable + for root, _, files in os.walk(self.theme_path): + st = os.stat(root) + os.chmod(root, st.st_mode | stat.S_IWUSR) + for name in files: + path = os.path.join(root, name) + st = os.stat(path) + os.chmod(path, st.st_mode | stat.S_IWUSR) + if self.settings["user_css"]: if not os.path.exists(self.settings["user_css"]): self.logger.error(