mirror of
https://git.deluge-torrent.org/deluge
synced 2025-04-21 03:54:50 +00:00
Don't run into loops when the auth file does not exist and we're trying to create it.
This commit is contained in:
parent
f6826a4f48
commit
f26de83509
3 changed files with 16 additions and 13 deletions
|
@ -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(),
|
||||
|
|
|
@ -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)")
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue