Skip to content
This repository has been archived by the owner on Apr 4, 2024. It is now read-only.

Commit

Permalink
Improve exception handling when renaming jails (#550)
Browse files Browse the repository at this point in the history
  • Loading branch information
jsegaert authored and Brandon Schneider committed May 11, 2018
1 parent 2593d90 commit a45ef09
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions iocage/lib/iocage.py
Expand Up @@ -1144,7 +1144,7 @@ def list(self,
exit_on_error=self.exit_on_error).list_datasets()

def rename(self, new_name):
uuid, _ = self.__check_jail_existence__()
uuid, old_mountpoint = self.__check_jail_existence__()
path = f"{self.pool}/iocage/jails/{uuid}"
new_path = path.replace(uuid, new_name)

Expand Down Expand Up @@ -1179,7 +1179,7 @@ def rename(self, new_name):
raise

try:
self.zfs.get_dataset(path).rename(new_path)
self.zfs.get_dataset(path).rename(new_path, False, True)
except libzfs.ZFSException:
raise

Expand All @@ -1197,14 +1197,17 @@ def rename(self, new_name):
silent=self.silent)

# Adjust mountpoints in fstab
old_mountpoint = f"{self.iocroot}/jails/{uuid}"
new_mountpoint = f"{self.iocroot}/jails/{new_name}"
new_mountpoint = old_mountpoint.replace(uuid, new_name)
jail_fstab = f"{new_mountpoint}/fstab"

with open(jail_fstab, "r") as fstab:
with ioc_common.open_atomic(jail_fstab, "w") as _fstab:
for line in fstab.readlines():
_fstab.write(line.replace(old_mountpoint, new_mountpoint))
try:
with open(jail_fstab, "r") as fstab:
with ioc_common.open_atomic(jail_fstab, "w") as _fstab:
for line in fstab.readlines():
_fstab.write(line.replace(old_mountpoint,
new_mountpoint))
except OSError:
pass

def restart(self, soft=False):
if self._all:
Expand Down

0 comments on commit a45ef09

Please sign in to comment.