Skip to content

Commit

Permalink
Add unmount parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
evilaliv3 committed Dec 28, 2024
1 parent 8a7d811 commit 81b5082
Showing 1 changed file with 28 additions and 1 deletion.
29 changes: 28 additions & 1 deletion src/globaleaks_eph_fs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import os
import re
import stat
import subprocess
import uuid
import threading
from fuse import FUSE, FuseOSError, Operations
Expand All @@ -14,7 +15,6 @@

UUID4_PATTERN = re.compile(r'^[0-9a-f]{8}-[0-9a-f]{4}-4[0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$', re.IGNORECASE)


def is_valid_uuid4(filename):
"""
Validates if the given filename follows the UUIDv4 format.
Expand All @@ -24,6 +24,24 @@ def is_valid_uuid4(filename):
"""
return bool(UUID4_PATTERN.match(filename))

def is_mount_point(path):
"""
Checks if the given path is a mount point.
A mount point is a directory where a filesystem is attached. This function checks
if the provided path is currently being used as a mount point by querying the
system's mount information.
:param path: The directory path to check if it is a mount point.
:return: True if the given path is a mount point, otherwise False.
:raises Exception: If there is an error while running the 'mount' command or parsing the result.
"""
try:
abs_path = os.path.abspath(path)
result = subprocess.run(['mount'], capture_output=True, text=True)
return any(abs_path in line for line in result.stdout.splitlines())
except:
return False

class EphemeralFile:
def __init__(self, filesdir, filename=None):
Expand Down Expand Up @@ -385,7 +403,16 @@ def main():
parser = argparse.ArgumentParser(description="GLOBALEAKS EPH FS")
parser.add_argument('mount_point', help="Path to mount the filesystem")
parser.add_argument('--storage_directory', '-s', help="Optional storage directory. Defaults to a temporary directory.")
parser.add_argument('--unmount', '-u', action='store_true', help="Unmount the filesystem if it's mounted.")
args = parser.parse_args()

if is_mount_point(args.mount_point):
print(f"Unmounting the filesystem at {args.mount_point}")
os.system(f"fusermount -u {args.mount_point}")

if args.unmount:
return

EphemeralFS(args.mount_point, args.storage_directory, foreground=True)

if __name__ == '__main__':
Expand Down

0 comments on commit 81b5082

Please sign in to comment.