Duplicate file receive logic in delta fallback path in file.c #54

Closed
opened 2026-07-20 17:14:08 +02:00 by TapTap · 0 comments
Owner

Description

In src/shared/file.c, the receive_delta_file() function (lines 263-303) contains duplicated code for receiving a file when delta transfer falls back (STATUS_NEXT after STATUS_DELTA_SIGNATURE). The decompression and metadata handling logic is essentially identical to file_receive() (lines 470-503).

Specifically, lines 267-303 duplicate the pattern of:

  1. Creating a File from the path
  2. Receiving metadata if use_metadata is set
  3. Receiving file data
  4. Decompressing if needed
  5. Setting the data on the file

Location

src/shared/file.c:263-303 and src/shared/file.c:470-503

Suggested Fix

Refactor receive_delta_file() to call file_receive() instead of duplicating the logic. The delta fallback path can use file_receive() and then return the received file directly.

if (resp == STATUS_NEXT) {
    delta_signature_destroy(sig);
    free(old_data);
    return file_receive(config, fd);  // reuse existing function
}

Severity

Medium

Category

Quality

## Description In `src/shared/file.c`, the `receive_delta_file()` function (lines 263-303) contains duplicated code for receiving a file when delta transfer falls back (`STATUS_NEXT` after `STATUS_DELTA_SIGNATURE`). The decompression and metadata handling logic is essentially identical to `file_receive()` (lines 470-503). Specifically, lines 267-303 duplicate the pattern of: 1. Creating a `File` from the path 2. Receiving metadata if `use_metadata` is set 3. Receiving file data 4. Decompressing if needed 5. Setting the data on the file ## Location `src/shared/file.c:263-303` and `src/shared/file.c:470-503` ## Suggested Fix Refactor `receive_delta_file()` to call `file_receive()` instead of duplicating the logic. The delta fallback path can use `file_receive()` and then return the received file directly. ```c if (resp == STATUS_NEXT) { delta_signature_destroy(sig); free(old_data); return file_receive(config, fd); // reuse existing function } ``` ## Severity Medium ## Category Quality
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: TapTap/FastSync#54