From 0c937074ebdcdc6cd5984e542b8bfbd351cc8315 Mon Sep 17 00:00:00 2001 From: "Soren I. Bjornstad" Date: Sat, 28 Jun 2014 11:22:07 -0500 Subject: [PATCH] prevent profiles from getting out of sync when rename fails If there is an error in renaming the folder, don't write the new profile name to the database. --- aqt/profiles.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/aqt/profiles.py b/aqt/profiles.py index 0b456350b..cc99fd26e 100644 --- a/aqt/profiles.py +++ b/aqt/profiles.py @@ -164,8 +164,22 @@ a flash drive.""" % self.base) self.db.execute("update profiles set name = ? where name = ?", name.encode("utf8"), oldName.encode("utf-8")) # rename folder - os.rename(oldFolder, newFolder) - self.db.commit() + try: + os.rename(oldFolder, newFolder) + except WindowsError as e: + self.db.rollback() + if "Access is denied" in e: + showWarning(_("""\ +Anki could not rename your profile because it could not rename the profile \ +folder on disk. Please ensure you have permission to write to Documents/Anki \ +and no other programs are accessing your profile folders, then try again.""")) + else: + raise + except: + self.db.rollback() + raise + else: + self.db.commit() # Folder handling ######################################################################