Refactor: send_files() and send_files_multithreaded() share massive code duplication #151
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Description
The two main transfer entry points in
src/client/client_send.ccontain significant duplicated code:1. Dry-run logic is duplicated (51 identical lines)
send_files()lines 361–380send_files_multithreaded()lines 501–520Both functions create a scanner, iterate chunks, count files/bytes, print output, and return — with identical logic.
2. Scanner creation is duplicated (9 identical arguments)
send_files()lines 416–419send_files_multithreaded()(insidescan_directory_multithreaded) lines 300–304Both call
directory_scanner_create()with the same 9 arguments: root_directory, use_metadata, chunk_size, exclude_patterns, exclude_count, include_patterns, include_count, max_size, min_size.3. Connection setup is duplicated (3 connection paths, same pattern)
The TCP / TLS / SSH connection logic appears in both
send_files()(lines 383–410) andsend_chunks_multithreaded()(lines 225–252) — the code is structurally identical.4. Manifest sending is duplicated
The code to serialize and send
ArrayList* manifestviaSTATUS_MANIFESTappears in bothsend_files()(lines 462–478) andsend_chunks_multithreaded()(lines 264–273).Location
src/client/client_send.c:361-380,:416-419,:462-478,:500-520andsrc/client/client_send.c:225-252,:264-273,:300-304Suggested Fix
static int dry_run(Config* config).static Client* connect_client(Config* config).static bool send_manifest(int fd, ArrayList* manifest).Severity
Medium
Category
Quality / Maintainability