mirror of
https://github.com/onionshare/onionshare.git
synced 2025-01-25 10:42:58 -03:00
In CLI, validate downloads_dir when starting in receive mode
This commit is contained in:
parent
e980bc153b
commit
878dd4f880
2 changed files with 30 additions and 12 deletions
|
@ -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)
|
||||
|
||||
|
|
|
@ -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: {}"
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue