pmb.helpers.mount: bind_file: Add create_folders option (!1861)

Create the necessary directory structure if create_folders=True.
This commit is contained in:
Minecrell 2020-01-20 13:31:13 +01:00 committed by Oliver Smith
parent f43d552039
commit 81d9bfe3ba
No known key found for this signature in database
GPG Key ID: 5AE7F5513E0885CB
1 changed files with 6 additions and 1 deletions

View File

@ -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