add: Command.receive_from_stream

This commit is contained in:
timeshifter
2021-12-02 15:23:32 +01:00
parent f28df3e4c6
commit 359a6a99a8
+7 -4
View File
@@ -274,10 +274,9 @@ class ZFS:
# -u File system that is associated with the received stream is not mounted. # -u File system that is associated with the received stream is not mounted.
if not isinstance(pool, Pool): if not isinstance(pool, Pool):
raise TypeError("Can only receive into pools.") raise TypeError("Can only receive into pools.")
# TODO use internal functions Command.receive_from_stream(
check_output(
[config.ZFS, "receive", "-d", "-F", "-u", pool.name], [config.ZFS, "receive", "-d", "-F", "-u", pool.name],
stdin=stream.stdout, stream,
) )
@classmethod @classmethod
@@ -489,7 +488,7 @@ class Snapshot:
class Command: class Command:
@staticmethod @staticmethod
def run(cmdline: list[str]): def run(cmdline: list[str]) -> None:
call(cmdline) call(cmdline)
@staticmethod @staticmethod
@@ -498,6 +497,10 @@ class Command:
cmdline = [cmdline] cmdline = [cmdline]
return check_output(cmdline).strip().decode() return check_output(cmdline).strip().decode()
@staticmethod
def receive_from_stream(cmdline: str | list[str], stream: Popen) -> None:
check_output(cmdline, stdin=stream.stdout)
def verify_running_as_root(): def verify_running_as_root():
if getuid() > 0: if getuid() > 0: