Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor format() #2512

Merged
merged 1 commit into from
May 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 17 additions & 32 deletions archinstall/lib/disk/device_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,49 +198,34 @@ def format(
path: Path,
additional_parted_options: List[str] = []
):
mkfs_type = fs_type.value
options = []
command = ''

match fs_type:
case FilesystemType.Btrfs:
options += ['-f']
command += 'mkfs.btrfs'
case FilesystemType.Fat16:
options += ['-F16']
command += 'mkfs.fat'
case FilesystemType.Fat32:
options += ['-F32']
command += 'mkfs.fat'
case FilesystemType.Ext2:
options += ['-F']
command += 'mkfs.ext2'
case FilesystemType.Ext3:
options += ['-F']
command += 'mkfs.ext3'
case FilesystemType.Ext4:
options += ['-F']
command += 'mkfs.ext4'
case FilesystemType.Xfs:
options += ['-f']
command += 'mkfs.xfs'
case FilesystemType.F2fs:
options += ['-f']
command += 'mkfs.f2fs'
case FilesystemType.Btrfs | FilesystemType.F2fs | FilesystemType.Xfs:
# Force overwrite
options.append('-f')
case FilesystemType.Ext2 | FilesystemType.Ext3 | FilesystemType.Ext4:
# Force create
options.append('-F')
case FilesystemType.Fat16 | FilesystemType.Fat32:
mkfs_type = 'fat'
# Set FAT size
options.extend(('-F', fs_type.value.removeprefix(mkfs_type)))
case FilesystemType.Ntfs:
options += ['-f', '-Q']
command += 'mkfs.ntfs'
# Skip zeroing and bad sector check
options.append('--fast')
case FilesystemType.Reiserfs:
command += 'mkfs.reiserfs'
pass
case _:
raise UnknownFilesystemFormat(f'Filetype "{fs_type.value}" is not supported')

options += additional_parted_options
options_str = ' '.join(options)
cmd = [f'mkfs.{mkfs_type}', *options, *additional_parted_options, str(path)]

debug(f'Formatting filesystem: /usr/bin/{command} {options_str} {path}')
debug('Formatting filesystem:', ' '.join(cmd))

try:
SysCommand(f"/usr/bin/{command} {options_str} {path}")
SysCommand(cmd)
except SysCallError as err:
msg = f'Could not format {path} with {fs_type.value}: {err.message}'
error(msg)
Expand Down