diff --git a/gitlib/gitlib.py b/gitlib/gitlib.py index ac878ce..2fb9470 100755 --- a/gitlib/gitlib.py +++ b/gitlib/gitlib.py @@ -351,6 +351,9 @@ class OpengnsysGitLibrary: if not mountpoint is None: self.logger.debug(f"Unmounting {mountpoint}") subprocess.run(["/usr/bin/umount", mountpoint], check=True) + + # We've unmounted a new filesystem, update our filesystems list + self.mounts = self._parse_mounts() else: self.logger.debug(f"{device} is not mounted") @@ -365,18 +368,29 @@ class OpengnsysGitLibrary: # TODO: modprobe not working on oglive subprocess.run(["/usr/sbin/modprobe", module], check=False) - def _mount(self, device, mountpoint, filesystem): + def _mount(self, device, mountpoint, filesystem = None): self.logger.debug(f"Mounting {device} at {mountpoint}") + if not os.path.exists(mountpoint): + self.logger.debug(f"Creating directory {mountpoint}") + os.mkdir(mountpoint) + mount_cmd = ["/usr/bin/mount"] if not filesystem is None: mount_cmd = mount_cmd + ["-t", filesystem] - mount_cmd = mount_cmd + [mountpoint] + mount_cmd = mount_cmd + [device, mountpoint] self.logger.debug(f"Mount command: {mount_cmd}") - subprocess.run(mount_cmd, check=True) + result = subprocess.run(mount_cmd, check=True, capture_output = True) + + self.logger.debug(f"retorno: {result.returncode}") + self.logger.debug(f"stdout: {result.stdout}") + self.logger.debug(f"stderr: {result.stderr}") + + # We've mounted a new filesystem, update our filesystems list + self.mounts = self._parse_mounts() def _ntfsfix(self, device): @@ -543,19 +557,6 @@ class OpengnsysGitLibrary: self.logger.debug(f"stdout: {result.stdout}") self.logger.debug(f"stderr: {result.stderr}") - def _mount(self, device, directory): - self.logger.debug(f"Mounting {device} in {directory}") - - if not os.path.exists(directory): - os.mkdir(directory) - - - result = subprocess.run(["/usr/bin/mount", device, directory], check = True, capture_output=True) - - self.logger.debug(f"retorno: {result.returncode}") - self.logger.debug(f"stdout: {result.stdout}") - self.logger.debug(f"stderr: {result.stderr}") - def _grub_install(self, boot_device, root_directory): """ Install GRUB bootloader on the specified boot device. @@ -812,6 +813,7 @@ class OpengnsysGitLibrary: seen_roots = {} filesystems_data = {} ntfs_secaudit_list = [] + path_norm = os.path.normpath(path) git_dir = os.path.normpath(os.path.join(path, ".git")) @@ -868,6 +870,8 @@ class OpengnsysGitLibrary: if not root in seen_roots: seen_roots[root]=1 + mount_found = False + if root in self.mounts: mount = self.mounts[root] root_path_rel = root[len(path):None] @@ -919,7 +923,15 @@ class OpengnsysGitLibrary: #self._ntfs_secaudit(root, os.path.join(meta_dir, "ntfs_secaudit.txt")) ntfs = True + else: + if root_norm == path_norm: + errstr = f"""We've failed to find metadata for the root filesystem! + Root: {root} + FS data: """ + errstr = errstr + json.dumps(self.mounts) + self.logger.error(errstr) + raise RuntimeError(errstr) #self.logger.debug(f"Root rel: {root_rel}") if len(files) == 1 and files[0] == ".opengnsys-keep":