mirror of
https://codeberg.org/Reuh/feather.git
synced 2025-10-28 02:29:32 +00:00
fix: error if deleting an html file during sync and it was read on the server
This commit is contained in:
parent
f788279756
commit
f5d61b107c
2 changed files with 9 additions and 8 deletions
|
|
@ -20,7 +20,7 @@
|
||||||
- [x] Make HTML template configurable
|
- [x] Make HTML template configurable
|
||||||
- [ ] Nested categories
|
- [ ] Nested categories
|
||||||
- [ ] Share the fun somewhere
|
- [ ] 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
|
- [ ] Proper filename escaping
|
||||||
- [ ] Command to force regenerate all HTML files (incl. recompute datetimes & paths)
|
- [ ] Command to force regenerate all HTML files (incl. recompute datetimes & paths)
|
||||||
- [ ] Handle item updates
|
- [ ] Handle item updates
|
||||||
|
|
|
||||||
15
main.py
15
main.py
|
|
@ -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))
|
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"
|
json_path = config.json_root / f"{ sha256(item_json["id"].encode("utf-8")).hexdigest() }.json"
|
||||||
grabbed_item_paths.append(p)
|
grabbed_item_paths.append(json_path)
|
||||||
if not p.exists():
|
if not json_path.exists():
|
||||||
# write JSON
|
# write JSON
|
||||||
with p.open("w") as f:
|
with json_path.open("w") as f:
|
||||||
json.dump(item_json, f)
|
json.dump(item_json, f)
|
||||||
# write HTML
|
# write HTML
|
||||||
generate_html_for_item(config, item_json)
|
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:
|
if not item_path in grabbed_item_paths:
|
||||||
# remove HTML
|
# remove HTML
|
||||||
item_json = json.load(item_path.open("r"))
|
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
|
# remove JSON
|
||||||
item_path.unlink()
|
item_path.unlink()
|
||||||
removed_items += 1
|
removed_items += 1
|
||||||
|
|
@ -204,10 +204,11 @@ def generate_html_for_item(config, item_json):
|
||||||
with html_path.open("w") as f:
|
with html_path.open("w") as f:
|
||||||
f.write(config.item_template.render(item_json))
|
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
|
# Delete a HTML file for a JSON object
|
||||||
html_path = config.html_root / item_json["html_path"]
|
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):
|
def remove_empty_html_directories(config):
|
||||||
# Remove empty directories in the HTML directory
|
# Remove empty directories in the HTML directory
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue