From ddba8b8a5c0dbe130adc922cc1ecdcdf287c5942 Mon Sep 17 00:00:00 2001 From: Vadim Troshchinskiy Date: Mon, 16 Dec 2024 13:08:40 +0100 Subject: [PATCH] Make unmounting more robust --- gitlib/filesystem.py | 17 ++++++++++++++++- gitlib/gitlib.py | 5 ++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/gitlib/filesystem.py b/gitlib/filesystem.py index de8f22f..bbaa69e 100644 --- a/gitlib/filesystem.py +++ b/gitlib/filesystem.py @@ -169,7 +169,22 @@ class FilesystemLibrary: if not mountpoint is None: self.logger.debug(f"Unmounting {mountpoint}") - subprocess.run(["/usr/bin/umount", mountpoint], check=True) + + done = False + start_time = time.time() + timeout = 60 + + + while not done and (time.time() - start_time) < timeout: + ret = subprocess.run(["/usr/bin/umount", mountpoint], check=False, capture_output=True, encoding='utf-8') + if ret.returncode == 0: + done=True + else: + if "target is busy" in ret.stderr: + self.logger.debug("Filesystem busy, waiting. %.1f seconds left", timeout - (time.time() - start_time)) + time.sleep(0.1) + else: + raise subprocess.CalledProcessError(ret.returncode, ret.args, output=ret.stdout, stderr=ret.stderr) # We've unmounted a new filesystem, update our filesystems list self.update_mounts() diff --git a/gitlib/gitlib.py b/gitlib/gitlib.py index ce91fd0..b1be526 100755 --- a/gitlib/gitlib.py +++ b/gitlib/gitlib.py @@ -302,7 +302,9 @@ class OpengnsysGitLibrary: metadata_file = os.path.join(data["metadata_dir"], "ntfs_secaudit.txt") self.logger.debug(f"Unmounting {data['mountpoint']}...") - subprocess.run(["/usr/bin/umount", data["mountpoint"]], check = True) + self.fs.unmount(mountpoint=data["mountpoint"]) + #subprocess.run(["/usr/bin/umount", data["mountpoint"]], check = True) + result = subprocess.run(["/usr/bin/ntfssecaudit", "-b", data["device"]], check=True, capture_output=True) self.logger.debug(f"Remounting {data['device']} on {data['mountpoint']}...") @@ -566,6 +568,7 @@ class OpengnsysGitLibrary: def _getOgRepository(self, name): return f"{self.repo_user}@{self.repo_server}:{self.repo_image_path}/{name}.git" + def _ogGetOsType(self): return "Linux"