diff --git a/onionshare/__init__.py b/onionshare/__init__.py index 3ab5cfed..ec008f5d 100644 --- a/onionshare/__init__.py +++ b/onionshare/__init__.py @@ -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) diff --git a/share/locale/en.json b/share/locale/en.json index 8686ea13..3340afd4 100644 --- a/share/locale/en.json +++ b/share/locale/en.json @@ -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: {}" }