In CLI, validate downloads_dir when starting in receive mode

This commit is contained in:
Micah Lee 2018-03-06 07:40:57 -08:00
parent e980bc153b
commit 878dd4f880
No known key found for this signature in database
GPG key ID: 403C2657CD994F73
2 changed files with 30 additions and 12 deletions

View file

@ -72,22 +72,38 @@ def main(cwd=None):
if debug:
common.set_debug(debug)
# Validation
valid = True
for filename in filenames:
if not os.path.isfile(filename) and not os.path.isdir(filename):
print(strings._("not_a_file").format(filename))
valid = False
if not os.access(filename, os.R_OK):
print(strings._("not_a_readable_file").format(filename))
valid = False
if not valid:
sys.exit()
# Validate filenames
if not receive:
valid = True
for filename in filenames:
if not os.path.isfile(filename) and not os.path.isdir(filename):
print(strings._("not_a_file").format(filename))
valid = False
if not os.access(filename, os.R_OK):
print(strings._("not_a_readable_file").format(filename))
valid = False
if not valid:
sys.exit()
# Load settings
settings = Settings(config)
settings.load()
# In receive mode, validate downloads dir
if receive:
valid = True
if not os.path.isdir(settings.get('downloads_dir')):
try:
os.mkdir(settings.get('downloads_dir'), 0o700)
except:
print(strings._('error_cannot_create_downloads_dir').format(settings.get('downloads_dir')))
valid = False
if valid and not os.access(settings.get('downloads_dir'), os.W_OK):
print(strings._('error_downloads_dir_not_writable').format(settings.get('downloads_dir')))
valid = False
if not valid:
sys.exit()
# Create the Web object
web = Web(debug, stay_open, False, receive)

View file

@ -156,5 +156,7 @@
"gui_file_info": "{} Files, {}",
"gui_file_info_single": "{} File, {}",
"info_in_progress_downloads_tooltip": "{} download(s) in progress",
"info_completed_downloads_tooltip": "{} download(s) completed"
"info_completed_downloads_tooltip": "{} download(s) completed",
"error_cannot_create_downloads_dir": "Error creating downloads folder: {}",
"error_downloads_dir_not_writable": "The downloads folder isn't writable: {}"
}