From 81d9bfe3ba77cd9b955dc90e94fcab2b27dc6b32 Mon Sep 17 00:00:00 2001 From: Minecrell Date: Mon, 20 Jan 2020 13:31:13 +0100 Subject: [PATCH] pmb.helpers.mount: bind_file: Add create_folders option (!1861) Create the necessary directory structure if create_folders=True. --- pmb/helpers/mount.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pmb/helpers/mount.py b/pmb/helpers/mount.py index f80b3525..27157f20 100644 --- a/pmb/helpers/mount.py +++ b/pmb/helpers/mount.py @@ -66,7 +66,7 @@ def bind(args, source, destination, create_folders=True, umount=False): raise RuntimeError("Mount failed: " + source + " -> " + destination) -def bind_file(args, source, destination): +def bind_file(args, source, destination, create_folders=False): """ Mount a file with the --bind option, and create the destination file, if necessary. @@ -77,6 +77,11 @@ def bind_file(args, source, destination): # Create empty file if not os.path.exists(destination): + if create_folders: + dir = os.path.dirname(destination) + if not os.path.isdir(dir): + pmb.helpers.run.root(args, ["mkdir", "-p", dir]) + pmb.helpers.run.root(args, ["touch", destination]) # Mount