Module: deluge
Branch: chunked-sessionproxy-and-gtkui-speedups
Commit: f26de83509aa6e798b84aa847b7692d50184e708

Author: Pedro Algarvio <[email protected]>
Date:   Sun May  1 04:44:42 2011 +0100

Don't run into loops when the auth file does not exist and we're trying to 
create it.

---

 deluge/common.py           |    4 ++--
 deluge/core/authmanager.py |   14 ++++++++------
 deluge/tests/common.py     |   11 ++++++-----
 3 files changed, 16 insertions(+), 13 deletions(-)

diff --git a/deluge/common.py b/deluge/common.py
index ef9a5aa..533094f 100644
--- a/deluge/common.py
+++ b/deluge/common.py
@@ -652,7 +652,7 @@ def create_auth_file():
         # Change the permissions on the file so only this user can read/write 
it
         os.chmod(auth_file, stat.S_IREAD | stat.S_IWRITE)
 
-def create_localclient_account():
+def create_localclient_account(append=False):
     import configmanager, random
     auth_file = configmanager.get_config_dir("auth")
     if not os.path.exists(auth_file):
@@ -662,7 +662,7 @@ def create_localclient_account():
         from hashlib import sha1 as sha_hash
     except ImportError:
         from sha import new as sha_hash
-    fd = open(auth_file, "w")
+    fd = open(auth_file, "a" if append else "w")
     fd.write(":".join([
         "localclient",
         sha_hash(str(random.random())).hexdigest(),
diff --git a/deluge/core/authmanager.py b/deluge/core/authmanager.py
index 1f9528f..cd27801 100644
--- a/deluge/core/authmanager.py
+++ b/deluge/core/authmanager.py
@@ -196,7 +196,8 @@ class AuthManager(component.Component):
         new_auth_file = old_auth_file + '.new'
         bak_auth_file = old_auth_file + '.bak'
         # Let's first create a backup
-        shutil.copy2(old_auth_file, bak_auth_file)
+        if os.path.exists(old_auth_file):
+            shutil.copy2(old_auth_file, bak_auth_file)
 
         try:
             fd = open(new_auth_file, "w")
@@ -211,7 +212,8 @@ class AuthManager(component.Component):
             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)
+            if os.path.exists(bak_auth_file):
+                os.rename(bak_auth_file, old_auth_file)
 
         self.__load_auth_file()
 
@@ -220,9 +222,8 @@ class AuthManager(component.Component):
         auth_file = configmanager.get_config_dir("auth")
         # Check for auth file and create if necessary
         if not os.path.exists(auth_file):
-            create_auth_file()
             create_localclient_account()
-            self.write_auth_file()
+            return self.__load_auth_file()
 
         auth_file_modification_time = os.stat(auth_file).st_mtime
         if self.__auth_modification_time is None:
@@ -277,8 +278,9 @@ class AuthManager(component.Component):
             self.__auth[username] = Account(username, password, authlevel)
 
         if "localclient" not in self.__auth:
-            create_localclient_account()
-            self.write_auth_file()
+            create_localclient_account(True)
+            return self.__load_auth_file()
+
 
         if save_and_reload:
             log.info("Re-writing auth file (upgrade)")
diff --git a/deluge/tests/common.py b/deluge/tests/common.py
index 78d1739..c24cd4c 100644
--- a/deluge/tests/common.py
+++ b/deluge/tests/common.py
@@ -55,15 +55,16 @@ deluge.main.start_daemon()
         if "Factory starting on 58846" in line:
             time.sleep(0.3) # Slight pause just incase
             break
+        elif "Couldn't listen on localhost:58846" in line:
+            raise SystemExit("Could not start deluge test client. %s" % line)
         elif 'Traceback' in line:
             raise SystemExit(
-                "Failed to start core daemon. Do \"\"\"%s\"\"\" to see what's "
+                "Failed to start core daemon. Do \"\"\" %s \"\"\" to see 
what's "
                 "happening" %
-                "python -c \"import sys; import tempfile; "
-                "config_directory = tempfile.mkdtemp(); "
-                "import deluge.main; import deluge.configmanager; "
+                "python -c \"import sys; import tempfile; import deluge.main; "
+                "import deluge.configmanager; config_directory = 
tempfile.mkdtemp(); "
                 "deluge.configmanager.set_config_dir(config_directory); "
                 "sys.argv.extend(['-d', '-c', config_directory, '-L', 
'info']); "
-                "deluge.main.start_daemon()"
+                "deluge.main.start_daemon()\""
             )
     return core

-- 
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