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 @staticmethod
# TODO must take a Snapshot object def destroy_snapshot(snapshot: Snapshot, *, recursive=False):
def destroy(full_name, *, recursive=False): if not isinstance(snapshot, Snapshot):
# TODO condition must be "begins with" raise TypeError("Can only destroy snapshots.")
# or better argument should be a ZFSPath if config.local_pool_to_backup == snapshot.pool:
if config.local_pool_to_backup in full_name:
raise Exception(DELETE_IN_LOCAL_POOL) raise Exception(DELETE_IN_LOCAL_POOL)
cmdline = [config.ZFS, "destroy"] cmdline = [config.ZFS, "destroy"]
if recursive: if recursive:
cmdline.append("-r") cmdline.append("-r")
cmdline.append(full_name) cmdline.append(str(snapshot))
run_command(cmdline) run_command(cmdline)
@staticmethod @staticmethod
@@ -477,7 +476,7 @@ class Snapshot:
return bool(search(regex, str(self._path))) return bool(search(regex, str(self._path)))
def destroy(self): def destroy(self):
ZFS.destroy(str(self)) ZFS.destroy_snapshot(self)
@property @property
def pool(self) -> str: def pool(self) -> str: