Merge pull request #141 from Jip-Hop/develop

Support spaces in pool and dataset name
Closes #122
This commit is contained in:
Jip-Hop 2024-04-26 16:55:49 +02:00 committed by GitHub
commit ea208ba955
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 4 deletions

View File

@ -4,7 +4,7 @@
with full access to all files via bind mounts, \ with full access to all files via bind mounts, \
thanks to systemd-nspawn!""" thanks to systemd-nspawn!"""
__version__ = "1.2.0" __version__ = "1.2.1"
__disclaimer__ = """USE THIS SCRIPT AT YOUR OWN RISK! __disclaimer__ = """USE THIS SCRIPT AT YOUR OWN RISK!
IT COMES WITHOUT WARRANTY AND IS NOT SUPPORTED BY IXSYSTEMS.""" IT COMES WITHOUT WARRANTY AND IS NOT SUPPORTED BY IXSYSTEMS."""
@ -923,12 +923,17 @@ def get_zfs_dataset(path):
""" """
Get ZFS dataset path. Get ZFS dataset path.
""" """
def clean_field(field):
# Put back spaces which were encoded
# https://github.com/openzfs/zfs/issues/11182
return field.replace('\\040', ' ')
path = os.path.realpath(path) path = os.path.realpath(path)
with open("/proc/mounts", "r") as f: with open("/proc/mounts", "r") as f:
for line in f: for line in f:
fields = line.split() fields = line.split()
if fields[1] == path and fields[2] == "zfs": if "zfs" == fields[2] and path == clean_field(fields[1]):
return fields[0] return clean_field(fields[0])
def get_zfs_base_path(): def get_zfs_base_path():
@ -955,7 +960,7 @@ def create_zfs_dataset(relative_path):
def remove_zfs_dataset(relative_path): def remove_zfs_dataset(relative_path):
""" """
Remove a ZFS Dataset. Remove a ZFS Dataset.
Receives the dataset to be created relative to the jailmaker script (e.g. "jails/oldjail"). Receives the dataset to be removed relative to the jailmaker script (e.g. "jails/oldjail").
""" """
dataset_to_remove = os.path.join((get_zfs_base_path()), relative_path) dataset_to_remove = os.path.join((get_zfs_base_path()), relative_path)
eprint(f"Removing ZFS Dataset {dataset_to_remove}") eprint(f"Removing ZFS Dataset {dataset_to_remove}")
@ -1556,6 +1561,7 @@ def remove_jail(jail_name):
eprint(f"A jail with name {jail_name} does not exist.") eprint(f"A jail with name {jail_name} does not exist.")
return 1 return 1
# TODO: print which dataset is about to be removed before the user confirmation
check = input(f'\nCAUTION: Type "{jail_name}" to confirm jail deletion!\n\n') check = input(f'\nCAUTION: Type "{jail_name}" to confirm jail deletion!\n\n')
if check == jail_name: if check == jail_name: