mirror of
https://codeberg.org/privacy1st/subprocess-util
synced 2024-12-22 22:06:05 +01:00
refactor
This commit is contained in:
parent
44f88601fb
commit
e06409fdce
@ -26,7 +26,8 @@ def main():
|
||||
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser(prog='btrfs-receive-chunks-active')
|
||||
parser = argparse.ArgumentParser(prog='btrfs-receive-chunks-active',
|
||||
description='Either CHILD_SUBVOLUME or SOURCE_CHUNK_DIR must be given')
|
||||
|
||||
parser.add_argument('--chunk-dir',
|
||||
help='Chunks are saved in this directory. '
|
||||
|
@ -72,8 +72,21 @@ def exec_receive_chunks_active(
|
||||
break
|
||||
chunk_no += 1
|
||||
|
||||
# Create the local chunk directory.
|
||||
if target_chunk_dir.exists():
|
||||
created_chunk_dir = False
|
||||
else:
|
||||
target_chunk_dir.mkdir(parents=True, exist_ok=False)
|
||||
created_chunk_dir = True
|
||||
|
||||
returncode = execute_consume_chunks(
|
||||
command=command,
|
||||
handle_chunks=handle_chunks,
|
||||
)
|
||||
|
||||
# If no errors occurred, delete the chunk directory.
|
||||
# But only if we created it ourselves!
|
||||
if returncode == 0 and created_chunk_dir:
|
||||
target_chunk_dir.unlink(missing_ok=False)
|
||||
|
||||
return returncode
|
||||
|
@ -45,10 +45,23 @@ def exec_send_chunks_passive(
|
||||
chunk_transferred_sock.close()
|
||||
chunk_transferred_sock_path.unlink(missing_ok=False)
|
||||
|
||||
# Create the local chunk directory.
|
||||
if source_chunk_dir.exists():
|
||||
created_chunk_dir = False
|
||||
else:
|
||||
source_chunk_dir.mkdir(parents=True, exist_ok=False)
|
||||
created_chunk_dir = True
|
||||
|
||||
returncode = execute_produce_chunks(
|
||||
command=command,
|
||||
get_chunk_path=get_source_chunk_path,
|
||||
handle_chunk=handle_chunk,
|
||||
chunk_size=chunk_size,
|
||||
)
|
||||
|
||||
# If no errors occurred, delete the chunk directory.
|
||||
# But only if we created it ourselves!
|
||||
if returncode == 0 and created_chunk_dir:
|
||||
source_chunk_dir.unlink(missing_ok=False)
|
||||
|
||||
return returncode
|
||||
|
@ -40,8 +40,21 @@ def exec_receive_chunks_passive(
|
||||
sock.close()
|
||||
target_socket.unlink(missing_ok=False)
|
||||
|
||||
# Create the local chunk directory.
|
||||
if target_chunk_dir.exists():
|
||||
created_chunk_dir = False
|
||||
else:
|
||||
target_chunk_dir.mkdir(parents=True, exist_ok=False)
|
||||
created_chunk_dir = True
|
||||
|
||||
returncode = execute_consume_chunks(
|
||||
command=command,
|
||||
handle_chunks=handle_chunks,
|
||||
)
|
||||
|
||||
# If no errors occurred, delete the chunk directory.
|
||||
# But only if we created it ourselves!
|
||||
if returncode == 0 and created_chunk_dir:
|
||||
target_chunk_dir.unlink(missing_ok=False)
|
||||
|
||||
return returncode
|
||||
|
@ -41,10 +41,23 @@ def exec_send_chunks_active(
|
||||
source_chunk_path.unlink(missing_ok=False)
|
||||
repeat_until_successful(inform_cmd, usr_confirmation_socket)
|
||||
|
||||
# Create the local chunk directory.
|
||||
if source_chunk_dir.exists():
|
||||
created_chunk_dir = False
|
||||
else:
|
||||
source_chunk_dir.mkdir(parents=True, exist_ok=False)
|
||||
created_chunk_dir = True
|
||||
|
||||
returncode = execute_produce_chunks(
|
||||
command=command,
|
||||
get_chunk_path=get_source_chunk_path,
|
||||
handle_chunk=handle_chunk,
|
||||
chunk_size=chunk_size,
|
||||
)
|
||||
|
||||
# If no errors occurred, delete the chunk directory.
|
||||
# But only if we created it ourselves!
|
||||
if returncode == 0 and created_chunk_dir:
|
||||
source_chunk_dir.unlink(missing_ok=False)
|
||||
|
||||
return returncode
|
||||
|
Loading…
Reference in New Issue
Block a user