This commit is contained in:
Daniel Langbein 2023-03-19 20:10:06 +01:00
parent 44f88601fb
commit e06409fdce
5 changed files with 54 additions and 1 deletions

View File

@ -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. '

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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