Module: deluge
Branch: master
Commit: 936bd925d98bd518fc483e16477a708cb5d47b21

Author: Pedro Algarvio <[email protected]>
Date:   Mon Apr 25 08:12:46 2011 +0100

Some changes were left behind on last commit.

---

 deluge/core/authmanager.py |   32 +++++++++++++++++++++++---------
 1 files changed, 23 insertions(+), 9 deletions(-)

diff --git a/deluge/core/authmanager.py b/deluge/core/authmanager.py
index bed8ec0..4e07089 100644
--- a/deluge/core/authmanager.py
+++ b/deluge/core/authmanager.py
@@ -37,6 +37,7 @@
 import os
 import random
 import stat
+import shutil
 import logging
 
 import deluge.component as component
@@ -133,6 +134,9 @@ class AuthManager(component.Component):
         else:
             raise BadLoginError("Password does not match", username)
 
+    def has_account(self, username):
+        return username in self.__auth
+
     def get_known_accounts(self):
         """
         Returns a list of known deluge usernames.
@@ -180,15 +184,25 @@ class AuthManager(component.Component):
     def write_auth_file(self):
         old_auth_file = configmanager.get_config_dir("auth")
         new_auth_file = old_auth_file + '.new'
-        fd = open(new_auth_file, "w")
-        for account in self.__auth.values():
-            fd.write(
-                "%(username)s:%(password)s:%(authlevel_int)s\n" % 
account.data()
-            )
-        fd.flush()
-        os.fsync(fd.fileno())
-        fd.close()
-        os.rename(new_auth_file, old_auth_file)
+        bak_auth_file = old_auth_file + '.bak'
+        # Let's first create a backup
+        shutil.copy2(old_auth_file, bak_auth_file)
+
+        try:
+            fd = open(new_auth_file, "w")
+            for account in self.__auth.values():
+                fd.write(
+                    "%(username)s:%(password)s:%(authlevel_int)s\n" %
+                    account.data()
+                )
+            fd.flush()
+            os.fsync(fd.fileno())
+            fd.close()
+            os.rename(new_auth_file, old_auth_file)
+        except:
+            # Something failed, let's restore the previous file
+            os.rename(bak_auth_file, old_auth_file)
+
         self.__load_auth_file()
 
     def __create_localclient_account(self):

-- 
You received this message because you are subscribed to the Google Groups 
"deluge-commit" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/deluge-commit?hl=en.

Reply via email to