From: Oleg Broytman Date: Wed, 20 Aug 2025 18:06:00 +0000 (+0300) Subject: Feat(mv): Begin/commit transaction X-Git-Url: https://git.phdru.name/?a=commitdiff_plain;h=2493cc4bf9b39d9e41fe8676b41ebe47e6b4a525;p=xsetbg.git Feat(mv): Begin/commit transaction Abort in case of an error. --- diff --git a/mv.py b/mv.py index d727f28..9adf21f 100755 --- a/mv.py +++ b/mv.py @@ -8,6 +8,8 @@ This file is a part of XSetBg. import os import sys +from sqlobject.sqlbuilder import LIKE + from xsetbg_db import xsetbg_db if not xsetbg_db: @@ -34,10 +36,16 @@ if os.path.exists(to_filename): from_filename = os.path.abspath(from_filename) to_filename = os.path.abspath(to_filename) +connection = xsetbg_db._connection +txn = connection.transaction() +xsetbg_db._connection = txn + rows = list(xsetbg_db.selectBy(full_name=from_filename)) if not rows: sys.exit("No rows by filename %s" % from_filename) row = rows[0] row.full_name = to_filename + os.rename(from_filename, to_filename) +txn.commit()