From b9a2bf786cdd26d5769af9f3e9a3eb9a5e39160f Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Thu, 2 Jul 2009 03:48:03 +0000 Subject: [PATCH] Write out the new auth file right away and do not re-read the file if doing so --- deluge/core/authmanager.py | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/deluge/core/authmanager.py b/deluge/core/authmanager.py index 9e29118bd..db24e2f2f 100644 --- a/deluge/core/authmanager.py +++ b/deluge/core/authmanager.py @@ -33,7 +33,7 @@ # # -import os.path +import os import random import stat @@ -101,12 +101,19 @@ 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): - open(auth_file, "w").write(self.__create_localclient_account()) + localclient = self.__create_localclient_account() + fd = open(auth_file, "w") + fd.write(localclient) + fd.flush() + os.fsync(fd.fileno()) + fd.close() # Change the permissions on the file so only this user can read/write it os.chmod(auth_file, stat.S_IREAD | stat.S_IWRITE) + f = [localclient] + else: + # Load the auth file into a dictionary: {username: password, ...} + f = open(auth_file, "r").readlines() - # Load the auth file into a dictionary: {username: password, ...} - f = open(auth_file, "r") for line in f: if line.startswith("#"): # This is a comment line @@ -128,6 +135,5 @@ class AuthManager(component.Component): self.__auth[username.strip()] = (password.strip(), level) - f.close() if "localclient" not in self.__auth: open(auth_file, "a").write(self.__create_localclient_account())