mirror of
https://github.com/onionshare/onionshare.git
synced 2025-01-26 11:13:00 -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:
|
if debug:
|
||||||
common.set_debug(debug)
|
common.set_debug(debug)
|
||||||
|
|
||||||
# Validation
|
# Validate filenames
|
||||||
valid = True
|
if not receive:
|
||||||
for filename in filenames:
|
valid = True
|
||||||
if not os.path.isfile(filename) and not os.path.isdir(filename):
|
for filename in filenames:
|
||||||
print(strings._("not_a_file").format(filename))
|
if not os.path.isfile(filename) and not os.path.isdir(filename):
|
||||||
valid = False
|
print(strings._("not_a_file").format(filename))
|
||||||
if not os.access(filename, os.R_OK):
|
valid = False
|
||||||
print(strings._("not_a_readable_file").format(filename))
|
if not os.access(filename, os.R_OK):
|
||||||
valid = False
|
print(strings._("not_a_readable_file").format(filename))
|
||||||
if not valid:
|
valid = False
|
||||||
sys.exit()
|
if not valid:
|
||||||
|
sys.exit()
|
||||||
|
|
||||||
# Load settings
|
# Load settings
|
||||||
settings = Settings(config)
|
settings = Settings(config)
|
||||||
settings.load()
|
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
|
# Create the Web object
|
||||||
web = Web(debug, stay_open, False, receive)
|
web = Web(debug, stay_open, False, receive)
|
||||||
|
|
||||||
|
|
|
@ -156,5 +156,7 @@
|
||||||
"gui_file_info": "{} Files, {}",
|
"gui_file_info": "{} Files, {}",
|
||||||
"gui_file_info_single": "{} File, {}",
|
"gui_file_info_single": "{} File, {}",
|
||||||
"info_in_progress_downloads_tooltip": "{} download(s) in progress",
|
"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