diff options
author | steviez <steve.czabaniuk@ni.com> | 2020-02-05 14:57:10 -0600 |
---|---|---|
committer | atrnati <54334261+atrnati@users.noreply.github.com> | 2020-02-18 10:37:25 -0600 |
commit | 28ca94661c365007916e05e8c84c3eaa7563c677 (patch) | |
tree | 26212c9e4ec3eefa39ca940b0c560a63d95a0339 /host/utils/uhd_images_downloader.py.in | |
parent | d7304cc724de43b0d61d5b9d61a528d58898f004 (diff) | |
download | uhd-28ca94661c365007916e05e8c84c3eaa7563c677.tar.gz uhd-28ca94661c365007916e05e8c84c3eaa7563c677.tar.bz2 uhd-28ca94661c365007916e05e8c84c3eaa7563c677.zip |
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
Diffstat (limited to 'host/utils/uhd_images_downloader.py.in')
-rw-r--r-- | host/utils/uhd_images_downloader.py.in | 13 |
1 files changed, 13 insertions, 0 deletions
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 |