mirror of
https://git.deluge-torrent.org/deluge
synced 2025-08-08 09:28:41 +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
|
# Change the permissions on the file so only this user can read/write it
|
||||||
os.chmod(auth_file, stat.S_IREAD | stat.S_IWRITE)
|
os.chmod(auth_file, stat.S_IREAD | stat.S_IWRITE)
|
||||||
|
|
||||||
def create_localclient_account():
|
def create_localclient_account(append=False):
|
||||||
import configmanager, random
|
import configmanager, random
|
||||||
auth_file = configmanager.get_config_dir("auth")
|
auth_file = configmanager.get_config_dir("auth")
|
||||||
if not os.path.exists(auth_file):
|
if not os.path.exists(auth_file):
|
||||||
|
@ -662,7 +662,7 @@ def create_localclient_account():
|
||||||
from hashlib import sha1 as sha_hash
|
from hashlib import sha1 as sha_hash
|
||||||
except ImportError:
|
except ImportError:
|
||||||
from sha import new as sha_hash
|
from sha import new as sha_hash
|
||||||
fd = open(auth_file, "w")
|
fd = open(auth_file, "a" if append else "w")
|
||||||
fd.write(":".join([
|
fd.write(":".join([
|
||||||
"localclient",
|
"localclient",
|
||||||
sha_hash(str(random.random())).hexdigest(),
|
sha_hash(str(random.random())).hexdigest(),
|
||||||
|
|
|
@ -196,6 +196,7 @@ class AuthManager(component.Component):
|
||||||
new_auth_file = old_auth_file + '.new'
|
new_auth_file = old_auth_file + '.new'
|
||||||
bak_auth_file = old_auth_file + '.bak'
|
bak_auth_file = old_auth_file + '.bak'
|
||||||
# Let's first create a backup
|
# Let's first create a backup
|
||||||
|
if os.path.exists(old_auth_file):
|
||||||
shutil.copy2(old_auth_file, bak_auth_file)
|
shutil.copy2(old_auth_file, bak_auth_file)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -211,6 +212,7 @@ class AuthManager(component.Component):
|
||||||
os.rename(new_auth_file, old_auth_file)
|
os.rename(new_auth_file, old_auth_file)
|
||||||
except:
|
except:
|
||||||
# Something failed, let's restore the previous file
|
# Something failed, let's restore the previous file
|
||||||
|
if os.path.exists(bak_auth_file):
|
||||||
os.rename(bak_auth_file, old_auth_file)
|
os.rename(bak_auth_file, old_auth_file)
|
||||||
|
|
||||||
self.__load_auth_file()
|
self.__load_auth_file()
|
||||||
|
@ -220,9 +222,8 @@ class AuthManager(component.Component):
|
||||||
auth_file = configmanager.get_config_dir("auth")
|
auth_file = configmanager.get_config_dir("auth")
|
||||||
# Check for auth file and create if necessary
|
# Check for auth file and create if necessary
|
||||||
if not os.path.exists(auth_file):
|
if not os.path.exists(auth_file):
|
||||||
create_auth_file()
|
|
||||||
create_localclient_account()
|
create_localclient_account()
|
||||||
self.write_auth_file()
|
return self.__load_auth_file()
|
||||||
|
|
||||||
auth_file_modification_time = os.stat(auth_file).st_mtime
|
auth_file_modification_time = os.stat(auth_file).st_mtime
|
||||||
if self.__auth_modification_time is None:
|
if self.__auth_modification_time is None:
|
||||||
|
@ -277,8 +278,9 @@ class AuthManager(component.Component):
|
||||||
self.__auth[username] = Account(username, password, authlevel)
|
self.__auth[username] = Account(username, password, authlevel)
|
||||||
|
|
||||||
if "localclient" not in self.__auth:
|
if "localclient" not in self.__auth:
|
||||||
create_localclient_account()
|
create_localclient_account(True)
|
||||||
self.write_auth_file()
|
return self.__load_auth_file()
|
||||||
|
|
||||||
|
|
||||||
if save_and_reload:
|
if save_and_reload:
|
||||||
log.info("Re-writing auth file (upgrade)")
|
log.info("Re-writing auth file (upgrade)")
|
||||||
|
|
|
@ -55,15 +55,16 @@ deluge.main.start_daemon()
|
||||||
if "Factory starting on 58846" in line:
|
if "Factory starting on 58846" in line:
|
||||||
time.sleep(0.3) # Slight pause just incase
|
time.sleep(0.3) # Slight pause just incase
|
||||||
break
|
break
|
||||||
|
elif "Couldn't listen on localhost:58846" in line:
|
||||||
|
raise SystemExit("Could not start deluge test client. %s" % line)
|
||||||
elif 'Traceback' in line:
|
elif 'Traceback' in line:
|
||||||
raise SystemExit(
|
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" %
|
"happening" %
|
||||||
"python -c \"import sys; import tempfile; "
|
"python -c \"import sys; import tempfile; import deluge.main; "
|
||||||
"config_directory = tempfile.mkdtemp(); "
|
"import deluge.configmanager; config_directory = tempfile.mkdtemp(); "
|
||||||
"import deluge.main; import deluge.configmanager; "
|
|
||||||
"deluge.configmanager.set_config_dir(config_directory); "
|
"deluge.configmanager.set_config_dir(config_directory); "
|
||||||
"sys.argv.extend(['-d', '-c', config_directory, '-L', 'info']); "
|
"sys.argv.extend(['-d', '-c', config_directory, '-L', 'info']); "
|
||||||
"deluge.main.start_daemon()"
|
"deluge.main.start_daemon()\""
|
||||||
)
|
)
|
||||||
return core
|
return core
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue