refactor: ZFS.destroy_snapshot

This commit is contained in:
timeshifter
2021-12-02 14:49:16 +01:00
parent 9a4bd5af2f
commit 17057806f3
+6 -7
View File
@@ -244,16 +244,15 @@ class ZFS:
]
@staticmethod
# TODO must take a Snapshot object
def destroy(full_name, *, recursive=False):
# TODO condition must be "begins with"
# or better argument should be a ZFSPath
if config.local_pool_to_backup in full_name:
def destroy_snapshot(snapshot: Snapshot, *, recursive=False):
if not isinstance(snapshot, Snapshot):
raise TypeError("Can only destroy snapshots.")
if config.local_pool_to_backup == snapshot.pool:
raise Exception(DELETE_IN_LOCAL_POOL)
cmdline = [config.ZFS, "destroy"]
if recursive:
cmdline.append("-r")
cmdline.append(full_name)
cmdline.append(str(snapshot))
run_command(cmdline)
@staticmethod
@@ -477,7 +476,7 @@ class Snapshot:
return bool(search(regex, str(self._path)))
def destroy(self):
ZFS.destroy(str(self))
ZFS.destroy_snapshot(self)
@property
def pool(self) -> str: