diff --git a/custom_syadmin/build_from_notion.py b/custom_syadmin/build_from_notion.py index 3bc693d..eb106ef 100644 --- a/custom_syadmin/build_from_notion.py +++ b/custom_syadmin/build_from_notion.py @@ -44,7 +44,7 @@ def get_value(name, default=False): return default -def rmrf(path): +def rmrf(path, keep_root=False): """ Use safe-rm for recursive removal """ """ @TODO: make it safer """ def remove_readonly(func, path, excinfo): @@ -53,7 +53,12 @@ def rmrf(path): # Try removal if os.path.exists(path) and len(os.path.realpath(path)) > 1: if os.path.isdir(path): - shutil.rmtree(path, onerror=remove_readonly) + if keep_root: + for root, dirs, files in os.walk(path): + for f in files: + os.remove(os.path.join(root, f)) + else: + shutil.rmtree(path, onerror=remove_readonly) elif os.path.isfile(path): os.remove(path) else: @@ -68,7 +73,7 @@ def cmd(parts, cwd=None, env=None): def hugo(hugo_site_path, dest, hugo_environment='gitea', base_url=None): """ builds the website to "dest" using "tmp" as an intermediate location """ - rmrf(dest) + rmrf(dest, keep_root=True) try: os.makedirs(dest, exist_ok=True) except: