From f3a9063c024396cb04908deda1f9643511108291 Mon Sep 17 00:00:00 2001 From: David Cantrell Date: Thu, 3 Sep 2009 16:52:19 -1000 Subject: Support a force=True argument on SwapSpace.create() force=True will tear down the device, unmount if necessary, and then reformat it. --- storage/formats/swap.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'storage') diff --git a/storage/formats/swap.py b/storage/formats/swap.py index 392ed11ae..e1dacb09d 100644 --- a/storage/formats/swap.py +++ b/storage/formats/swap.py @@ -132,10 +132,14 @@ class SwapSpace(DeviceFormat): """ Create the device. """ log_method_call(self, device=self.device, type=self.type, status=self.status) - if self.exists: + force = kwargs.get("force") + + if not force and self.exists: raise SwapSpaceError("format already exists") - if self.status: + if force: + self.teardown() + elif self.status: raise SwapSpaceError("device exists and is active") DeviceFormat.create(self, *args, **kwargs) -- cgit