utils: mount_mkdir success if target is a mountpoint

Returns true if target is already a mountpoint. Does not call mount.

It's possible that another device might be mounted in the target
mountpoint. A future check between the source and target for
equal device major:minor must be added.
more_events
Jose M. Guisado 2022-05-09 13:43:52 +02:00
parent 81ee4b02dd
commit 621d1b9147
1 changed files with 6 additions and 0 deletions

View File

@ -27,11 +27,17 @@ def find_mountpoint(path):
def mount_mkdir(source, target):
"""
Mounts and creates the mountpoint directory if it's not present.
Return True if mount is sucessful or if target is already a mountpoint.
"""
if not os.path.exists(target):
os.mkdir(target)
if not os.path.ismount(target):
return mount(source, target)
else:
return True
return False