From 28ca94661c365007916e05e8c84c3eaa7563c677 Mon Sep 17 00:00:00 2001 From: steviez Date: Wed, 5 Feb 2020 14:57:10 -0600 Subject: utils: image_downloader: check write conditions Prior to downloading any images, check that the images destination: - Is a valid directory - Has valid permissions for images to be written Images are downloaded to a temporary location before being written to image destination, so these checks help avoid situation where images are downloaded but unable to be written --- host/utils/uhd_images_downloader.py.in | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'host/utils') diff --git a/host/utils/uhd_images_downloader.py.in b/host/utils/uhd_images_downloader.py.in index 945b10c2d..1983ef84c 100644 --- a/host/utils/uhd_images_downloader.py.in +++ b/host/utils/uhd_images_downloader.py.in @@ -534,6 +534,19 @@ def main(): "\n".join("{}".format(item) for item in manifest.items()) )) + # Strip down path until we find first parent directory of images_dir + # that exists and then check if we have proper write permissions + images_dir_parent = images_dir + while not os.path.exists(os.path.abspath(images_dir_parent)): + path_pair = os.path.split(images_dir_parent) + if images_dir_parent == path_pair[0]: + # Prevent infinite loop + break + images_dir_parent = path_pair[0] + if not os.access(os.path.abspath(images_dir_parent), os.W_OK): + log("ERROR", "Invalid permissions to write images destination") + return False + # Read the inventory into a dictionary we can perform lookups on if os.path.isfile(args.inventory_location): inventory_fn = args.inventory_location -- cgit v1.2.3