1
0
Fork 0
mirror of https://codeberg.org/Reuh/feather.git synced 2025-10-27 18:19:32 +00:00

fix: error if deleting an html file during sync and it was read on the server

This commit is contained in:
Étienne Fildadut 2025-10-09 15:44:30 +02:00
parent f788279756
commit f5d61b107c
2 changed files with 9 additions and 8 deletions

View file

@ -20,7 +20,7 @@
- [x] Make HTML template configurable
- [ ] Nested categories
- [ ] Share the fun somewhere
- [ ] Edge cases: mark as read during sync (if marked as read on server or not)
- [x] Edge cases: mark as read during sync (if marked as read on server or not)
- [ ] Proper filename escaping
- [ ] Command to force regenerate all HTML files (incl. recompute datetimes & paths)
- [ ] Handle item updates

15
main.py
View file

@ -164,11 +164,11 @@ def synchronize_with_server(config, client_session):
}
item_json["html_path"] = str(get_html_path(config, item_json).relative_to(config.html_root))
p = config.json_root / f"{ sha256(item_json["id"].encode("utf-8")).hexdigest() }.json"
grabbed_item_paths.append(p)
if not p.exists():
json_path = config.json_root / f"{ sha256(item_json["id"].encode("utf-8")).hexdigest() }.json"
grabbed_item_paths.append(json_path)
if not json_path.exists():
# write JSON
with p.open("w") as f:
with json_path.open("w") as f:
json.dump(item_json, f)
# write HTML
generate_html_for_item(config, item_json)
@ -187,7 +187,7 @@ def synchronize_with_server(config, client_session):
if not item_path in grabbed_item_paths:
# remove HTML
item_json = json.load(item_path.open("r"))
remove_html_for_item(config, item_json)
remove_html_for_item(config, item_json, ignore_deleted=True) # ignore if file was deleted by user during sync
# remove JSON
item_path.unlink()
removed_items += 1
@ -204,10 +204,11 @@ def generate_html_for_item(config, item_json):
with html_path.open("w") as f:
f.write(config.item_template.render(item_json))
def remove_html_for_item(config, item_json):
def remove_html_for_item(config, item_json, ignore_deleted=False):
# Delete a HTML file for a JSON object
html_path = config.html_root / item_json["html_path"]
html_path.unlink()
if not ignore_deleted or html_path.exists():
html_path.unlink()
def remove_empty_html_directories(config):
# Remove empty directories in the HTML directory