( dev_path: Path, target_mountpoint: Path, mount_fs: str | None = None, create_target_mountpoint: bool = True, options: list[str] = [], )
| 137 | |
| 138 | |
| 139 | def mount( |
| 140 | dev_path: Path, |
| 141 | target_mountpoint: Path, |
| 142 | mount_fs: str | None = None, |
| 143 | create_target_mountpoint: bool = True, |
| 144 | options: list[str] = [], |
| 145 | ) -> None: |
| 146 | if create_target_mountpoint and not target_mountpoint.exists(): |
| 147 | target_mountpoint.mkdir(parents=True, exist_ok=True) |
| 148 | |
| 149 | if not target_mountpoint.exists(): |
| 150 | raise ValueError('Target mountpoint does not exist') |
| 151 | |
| 152 | lsblk_info = get_lsblk_info(dev_path) |
| 153 | if target_mountpoint in lsblk_info.mountpoints: |
| 154 | info(f'Device already mounted at {target_mountpoint}') |
| 155 | return |
| 156 | |
| 157 | cmd = ['mount'] |
| 158 | |
| 159 | if len(options): |
| 160 | cmd.extend(('-o', ','.join(options))) |
| 161 | if mount_fs: |
| 162 | cmd.extend(('-t', mount_fs)) |
| 163 | |
| 164 | cmd.extend((str(dev_path), str(target_mountpoint))) |
| 165 | |
| 166 | command = ' '.join(cmd) |
| 167 | |
| 168 | debug(f'Mounting {dev_path}: {command}') |
| 169 | |
| 170 | try: |
| 171 | SysCommand(command) |
| 172 | except SysCallError as err: |
| 173 | raise DiskError(f'Could not mount {dev_path}: {command}\n{err.message}') |
| 174 | |
| 175 | |
| 176 | def umount(mountpoint: Path, recursive: bool = False) -> None: |
no test coverage detected