From ace1b01da1048a5b4fc457487ca4e50320901f23 Mon Sep 17 00:00:00 2001 From: Lovens Weche Date: Thu, 17 Jan 2019 18:43:51 -0500 Subject: [PATCH] Fix addon manager crash if not finding the add-on (#3874) * Fix addon manager crash if not finding the add-on In the addon manager, there was no validation code for paths in the file system for uploading addons. This fix adds validation at the parsing level, so that the original code is left unchanged. * Fixes for addon manager crash commit Fixes include: 1. Spaces kept instead of tabs. 2. printf-style String Formatting is used since it seems to be compatible with nearly all versions of Python. 3. A trailing line break was added to the formatted string. --- data/tools/wesnoth_addon_manager | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/data/tools/wesnoth_addon_manager b/data/tools/wesnoth_addon_manager index 3090601db6d8..ecbeb3812eba 100755 --- a/data/tools/wesnoth_addon_manager +++ b/data/tools/wesnoth_addon_manager @@ -14,6 +14,15 @@ from subprocess import Popen import wesnoth.wmlparser3 as wmlparser from wesnoth.campaignserver_client import CampaignClient +# This is the validation code for the -u arguments. It checks if the input path is valid +def valid_file_path(path): + if os.path.isdir(path) or os.path.isfile(path): + return path + else: + sys.stderr.write("No such file or directory: %s\n" % path) + sys.exit(1) + return None + if __name__ == "__main__": import argparse @@ -65,7 +74,7 @@ if __name__ == "__main__": "UPLOAD should be either the name of an add-on subdirectory," + "(in which case the client looks for _server.pbl beneath it) " + "or a path to the .pbl file (in which case the name of the " + - "add-on subdirectory is the name of the path with .pbl removed)") + "add-on subdirectory is the name of the path with .pbl removed)", type=valid_file_path) argumentparser.add_argument("-s", "--status", help="Display the status of addons installed in the given " + "directory.")