From cb6b3340f8995605ad96a306fe0b5e6cbb57d1de Mon Sep 17 00:00:00 2001 From: Max Deineko Date: Sun, 4 Apr 2021 17:36:09 +0200 Subject: calcurse-caldav: always request href from server Apparently, while some CalDAV servers return href values as is in their response, some might return them URL-quoted (which, if I am not mistaken, was the reason for e943b06). Assuming either behaviour when pushing local objects will lead to discrepancy with events dictionary retrieved from the server and thus bugs, hence we always want to use whatever form of href the server returns. Addresses GitHub issues #337 and #356. Signed-off-by: Lukas Fleischer --- contrib/caldav/calcurse-caldav.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'contrib') diff --git a/contrib/caldav/calcurse-caldav.py b/contrib/caldav/calcurse-caldav.py index 1dfb5ae..3f57fdf 100755 --- a/contrib/caldav/calcurse-caldav.py +++ b/contrib/caldav/calcurse-caldav.py @@ -9,7 +9,6 @@ import re import subprocess import sys import textwrap -import urllib.parse import xml.etree.ElementTree as etree import httplib2 @@ -420,18 +419,21 @@ def push_object(conn, objhash): if not headers: return None - - etag = None headerdict = dict(headers) - if 'etag' in headerdict: - etag = headerdict['etag'] - while not etag: + + # Retrieve href from server to match server-side format. Retrieve ETag + # unless it can be extracted from the PUT response already. + ret_href, ret_etag = None, headerdict.get('etag') + while not ret_etag or not ret_href: etagdict = get_etags(conn, [href]) - if etagdict: - etag = next(iter(etagdict.values())) - etag = etag.strip('"') + if not etagdict: + continue + ret_href, new_etag = next(iter(etagdict.items())) + # Favor ETag from PUT response to avoid race condition. + if not ret_etag: + ret_etag = new_etag - return (urllib.parse.quote(href), etag) + return (ret_href, ret_etag.strip('"')) def push_objects(objhashes, conn, syncdb, etagdict): -- cgit v1.2.3-70-g09d2