From d4c20086e745d3eb61de6fdbeba88792e10b83f5 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Wed, 28 Dec 2022 20:31:06 +0100 Subject: lock track directory when editing This is important if concurrent requests to edit the same track are made, both for images and later for metadata embedding. --- fietsboek/views/edit.py | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/fietsboek/views/edit.py b/fietsboek/views/edit.py index a26452d..b3dcf1e 100644 --- a/fietsboek/views/edit.py +++ b/fietsboek/views/edit.py @@ -81,20 +81,22 @@ def do_edit(request): if any(user not in track.tagged_people and user not in user_friends for user in tagged_people): return HTTPBadRequest() + data = request.data_manager.open(track.id) tz_offset = datetime.timedelta(minutes=int(request.params["date-tz"])) date = datetime.datetime.fromisoformat(request.params["date"]) - track.date = date.replace(tzinfo=datetime.timezone(tz_offset)) - - track.tagged_people = tagged_people - track.title = request.params["title"] - track.visibility = Visibility[request.params["visibility"]] - track.type = TrackType[request.params["type"]] - track.description = request.params["description"] - track.badges = badges - tags = request.params.getall("tag[]") - track.sync_tags(tags) - - edit_images(request, request.context) + with data.lock(): + track.date = date.replace(tzinfo=datetime.timezone(tz_offset)) + + track.tagged_people = tagged_people + track.title = request.params["title"] + track.visibility = Visibility[request.params["visibility"]] + track.type = TrackType[request.params["type"]] + track.description = request.params["description"] + track.badges = badges + tags = request.params.getall("tag[]") + track.sync_tags(tags) + + edit_images(request, request.context) return HTTPFound(request.route_url("details", track_id=track.id)) -- cgit v1.2.3