Skip to content

Commit

Permalink
Fix addon manager crash if not finding the add-on (#3874)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
LovCAPONE authored and Vultraz committed Jan 17, 2019
1 parent 4679e55 commit ace1b01
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion data/tools/wesnoth_addon_manager
Expand Up @@ -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

Expand Down Expand Up @@ -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.")
Expand Down

0 comments on commit ace1b01

Please sign in to comment.