Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| cb671bade0 | |||
| 4feb75957a | |||
| d529360c01 | |||
| 8743d7f522 | |||
| 05a74770ca | |||
| 98cb8e212e | |||
| dd11f70043 | |||
| 0b68974b42 | |||
| df41e8bd06 | |||
| 1064ae6c19 | |||
| bf91c5b588 | |||
| 5eaea9d92e | |||
| 9d67fcbf92 | |||
| 261683aaff | |||
| 15a861747a | |||
| 5f1b27c8ff | |||
| 732cd67735 | |||
| 50fb7185a8 | |||
| 3062927e07 | |||
| 5d74c7cb74 | |||
| efc7e062e3 | |||
| 88746c3396 |
@@ -206,7 +206,7 @@ tea pr close <number> --repo TapTap/FastSync
|
|||||||
|
|
||||||
## Common pitfalls
|
## Common pitfalls
|
||||||
|
|
||||||
- **`__thread` on shared SSL context**: io_ssl must NOT be thread-local — worker threads inherit the SSL context from the main thread. Use regular `static SSL* io_ssl`.
|
- **Per-thread SSL context**: `io_ssl` is stored per-thread (`static __thread SSL* io_ssl`). Each thread that performs protocol I/O must call `io_set_ssl()` to install its own SSL object before using `send_*` / `receive_*` primitives. The main thread's SSL context is not automatically inherited by worker threads.
|
||||||
- **SSL WANT_READ/WANT_WRITE retry**: Always retry on `SSL_ERROR_WANT_READ` and `SSL_ERROR_WANT_WRITE` in `send_n_data`/`receive_n_data`. Removing these breaks TLS multithreaded transfers.
|
- **SSL WANT_READ/WANT_WRITE retry**: Always retry on `SSL_ERROR_WANT_READ` and `SSL_ERROR_WANT_WRITE` in `send_n_data`/`receive_n_data`. Removing these breaks TLS multithreaded transfers.
|
||||||
- **clang-format version**: The CI image uses clang-format 18. Always format inside the CI Docker container for exact match.
|
- **clang-format version**: The CI image uses clang-format 18. Always format inside the CI Docker container for exact match.
|
||||||
- **Merge order matters**: Merge the most comprehensive branch first, then smaller ones, to minimize conflicts when creating a combined branch.
|
- **Merge order matters**: Merge the most comprehensive branch first, then smaller ones, to minimize conflicts when creating a combined branch.
|
||||||
|
|||||||
+2
-1
@@ -79,8 +79,9 @@ set(TEST_INCLUDES tests src/shared src/server src/client)
|
|||||||
|
|
||||||
# Monolithic test binary (backward compatible)
|
# Monolithic test binary (backward compatible)
|
||||||
file(GLOB TEST_SRCS "tests/test_*.c" "tests/runner.c")
|
file(GLOB TEST_SRCS "tests/test_*.c" "tests/runner.c")
|
||||||
add_executable(tests ${TEST_SRCS} ${SHARED_SRCS} src/client/scanner.c)
|
add_executable(tests ${TEST_SRCS} ${SHARED_SRCS} src/client/scanner.c src/client/client_cli.c)
|
||||||
target_include_directories(tests PRIVATE ${TEST_INCLUDES})
|
target_include_directories(tests PRIVATE ${TEST_INCLUDES})
|
||||||
|
target_compile_definitions(tests PRIVATE FASTSYNC_TEST_BUILD)
|
||||||
target_link_libraries(tests PRIVATE ${TEST_LIBS})
|
target_link_libraries(tests PRIVATE ${TEST_LIBS})
|
||||||
add_test(NAME unit_all COMMAND tests)
|
add_test(NAME unit_all COMMAND tests)
|
||||||
|
|
||||||
|
|||||||
+274
@@ -0,0 +1,274 @@
|
|||||||
|
# Rsync Feature Compatibility
|
||||||
|
|
||||||
|
This document maps rsync's full feature set to FastSync's current implementation status.
|
||||||
|
|
||||||
|
## Summary
|
||||||
|
|
||||||
|
| Status | Count | Description |
|
||||||
|
|--------|-------|-------------|
|
||||||
|
| ✅ Implemented | 39 | Feature works end-to-end |
|
||||||
|
| 🔀 Alt Arg | 5 | Functionality exists but under different flag/semantics |
|
||||||
|
| ⚠️ Partial | 30 | Flag parsed/stored but behavior incomplete |
|
||||||
|
| ❌ Not Implemented | 62 | Flag not recognized or no behavior |
|
||||||
|
| **Total** | **136** | |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## 1. General Options
|
||||||
|
|
||||||
|
| Flag | Rsync Description | FastSync Status | Notes |
|
||||||
|
|------|-------------------|-----------------|-------|
|
||||||
|
| `-a`, `--archive` | Archive mode is -rlptgoD | 🔀 Alt Arg | Maps to -c -m -M (compression + multithread + metadata) |
|
||||||
|
| `-v`, `--verbose` | Increase verbosity | ✅ Implemented | Sets `log_level=DEBUG` |
|
||||||
|
| `-q`, `--quiet` | Suppress non-error messages | ✅ Implemented | `quiet` config field |
|
||||||
|
| `-h`, `--help` | Show help | ✅ Implemented | Prints usage and exits |
|
||||||
|
| `-V`, `--version` | Print version | ❌ Not Implemented | |
|
||||||
|
| `--info=FLAGS` | Fine-grained info verbosity | ⚠️ Partial | `info_level` stored, not wired |
|
||||||
|
| `--debug=FLAGS` | Fine-grained debug verbosity | ⚠️ Partial | `debug_level` stored, not wired |
|
||||||
|
| `--stderr=MODE` | Change stderr output mode | ❌ Not Implemented | |
|
||||||
|
| `--no-motd` | Suppress daemon MOTD | ❌ Not Implemented | |
|
||||||
|
| `--exclude=PATTERN` | Exclude files matching pattern | ✅ Implemented | Glob matching in scanner |
|
||||||
|
| `--include=PATTERN` | Include files matching pattern | ✅ Implemented | Glob matching in scanner |
|
||||||
|
| `-C`, `--cvs-exclude` | Auto-ignore CVS files | ⚠️ Partial | `cvs_exclude` stored, not wired |
|
||||||
|
|
||||||
|
## 2. Modifying Output
|
||||||
|
|
||||||
|
| Flag | Rsync Description | FastSync Status | Notes |
|
||||||
|
|------|-------------------|-----------------|-------|
|
||||||
|
| `--stats` | Give transfer stats | ✅ Implemented | Prints file/byte counts |
|
||||||
|
| `-h`, `--human-readable` | Human-readable numbers | ⚠️ Partial | `human_readable` stored, not wired |
|
||||||
|
| `-i`, `--itemize-changes` | Per-file change summary | ⚠️ Partial | `itemize_changes` stored, not wired |
|
||||||
|
| `--progress` | Show progress | ✅ Implemented | Progress callback in sender |
|
||||||
|
| `-P` | Same as --partial --progress | ❌ Not Implemented | |
|
||||||
|
| `--out-format=FORMAT` | Custom output format | ⚠️ Partial | `out_format` stored, not wired |
|
||||||
|
| `--log-file=FILE` | Log to file | ✅ Implemented | `log_file` config field |
|
||||||
|
| `--log-file-format=FMT` | Log format | ❌ Not Implemented | |
|
||||||
|
| `--8-bit-output` | Leave high-bit chars unescaped | ❌ Not Implemented | |
|
||||||
|
| `--list-only` | List files instead of copying | ⚠️ Partial | `list_only` stored, not wired |
|
||||||
|
|
||||||
|
## 3. File Selection
|
||||||
|
|
||||||
|
| Flag | Rsync Description | FastSync Status | Notes |
|
||||||
|
|------|-------------------|-----------------|-------|
|
||||||
|
| `--exclude-from=FILE` | Read exclude patterns from file | ✅ Implemented | Reads patterns from file |
|
||||||
|
| `--include-from=FILE` | Read include patterns from file | ✅ Implemented | Reads patterns from file |
|
||||||
|
| `--filter=RULE` | Add file-filtering rule | ⚠️ Partial | `filters` ArrayList stored, not wired |
|
||||||
|
| `--files-from=FILE` | Read source file list from file | ⚠️ Partial | `files_from` stored, not wired |
|
||||||
|
| `-0`, `--from0` | Delimit *-from files with NULs | ❌ Not Implemented | |
|
||||||
|
| `--max-size=SIZE` | Skip files larger than SIZE | ✅ Implemented | `max_size` in scanner |
|
||||||
|
| `--min-size=SIZE` | Skip files smaller than SIZE | ✅ Implemented | `min_size` in scanner |
|
||||||
|
| `-I`, `--ignore-times` | Don't skip files matching size+time | ❌ Not Implemented | |
|
||||||
|
| `--size-only` | Skip based on size only | ❌ Not Implemented | |
|
||||||
|
| `-@`, `--modify-window=NUM` | Mod-time comparison accuracy | ❌ Not Implemented | |
|
||||||
|
| `--existing` | Skip creating new files on receiver | ❌ Not Implemented | |
|
||||||
|
| `--ignore-existing` | Skip updating existing files | ❌ Not Implemented | |
|
||||||
|
| `--remove-source-files` | Sender removes synced files | ❌ Not Implemented | |
|
||||||
|
|
||||||
|
## 4. Directory Options
|
||||||
|
|
||||||
|
| Flag | Rsync Description | FastSync Status | Notes |
|
||||||
|
|------|-------------------|-----------------|-------|
|
||||||
|
| `-r`, `--recursive` | Recurse into directories | ✅ Implemented | Default behavior |
|
||||||
|
| `-R`, `--relative` | Use relative path names | ⚠️ Partial | `relative` stored, not wired |
|
||||||
|
| `--no-implied-dirs` | Don't send implied dirs with -R | ❌ Not Implemented | |
|
||||||
|
| `-d`, `--dirs` | Transfer dirs without recursing | ❌ Not Implemented | |
|
||||||
|
| `--mkpath` | Create missing path components | ❌ Not Implemented | |
|
||||||
|
|
||||||
|
## 5. Transfer Modifications
|
||||||
|
|
||||||
|
| Flag | Rsync Description | FastSync Status | Notes |
|
||||||
|
|------|-------------------|-----------------|-------|
|
||||||
|
| `-u`, `--update` | Skip files newer on receiver | ⚠️ Partial | `update` stored, not wired |
|
||||||
|
| `--inplace` | Update files in-place | ✅ Implemented | Direct write mode |
|
||||||
|
| `--append` | Append data to shorter files | ⚠️ Partial | `append` stored, not wired |
|
||||||
|
| `--append-verify` | Append with old-data checksum | ⚠️ Partial | `append_verify` stored, not wired |
|
||||||
|
| `-W`, `--whole-file` | Copy whole file (no delta) | ❌ Not Implemented | |
|
||||||
|
| `--block-size=SIZE` | Force checksum block-size | ⚠️ Partial | Parsed as `--delta-block`; controls delta transfer block size |
|
||||||
|
|
||||||
|
## 6. Destination Handling
|
||||||
|
|
||||||
|
| Flag | Rsync Description | FastSync Status | Notes |
|
||||||
|
|------|-------------------|-----------------|-------|
|
||||||
|
| `-n`, `--dry-run` | Trial run with no changes | ✅ Implemented | `dry_run` config field |
|
||||||
|
| `-b`, `--backup` | Make backups of overwritten files | ✅ Implemented | Backup before overwrite |
|
||||||
|
| `--backup-dir=DIR` | Backup directory hierarchy | ✅ Implemented | `backup_dir` config field |
|
||||||
|
| `--suffix=SUFFIX` | Backup suffix (default ~) | ✅ Implemented | `suffix` config field |
|
||||||
|
| `--delay-updates` | Put updated files in place at end | ❌ Not Implemented | |
|
||||||
|
|
||||||
|
## 7. Deletion
|
||||||
|
|
||||||
|
| Flag | Rsync Description | FastSync Status | Notes |
|
||||||
|
|------|-------------------|-----------------|-------|
|
||||||
|
| `--delete` | Delete extraneous files from dest | ✅ Implemented | `use_delete` config field |
|
||||||
|
| `--delete-before` | Delete before transfer | ⚠️ Partial | `delete_before` stored, not wired |
|
||||||
|
| `--delete-during` | Delete during transfer | ❌ Not Implemented | |
|
||||||
|
| `--delete-delay` | Find deletions during, delete after | ❌ Not Implemented | |
|
||||||
|
| `--delete-after` | Delete after transfer | ⚠️ Partial | `delete_after` stored, not wired |
|
||||||
|
| `--delete-excluded` | Also delete excluded files | ⚠️ Partial | `delete_excluded` stored, not wired |
|
||||||
|
| `--max-delete=NUM` | Max files to delete | ⚠️ Partial | `max_delete` stored, not wired |
|
||||||
|
| `--ignore-errors` | Delete even with I/O errors | ❌ Not Implemented | |
|
||||||
|
| `--force` | Force deletion of non-empty dirs | ❌ Not Implemented | |
|
||||||
|
| `--prune-empty-dirs` | Prune empty dir chains | ⚠️ Partial | `prune_empty_dirs` stored, not wired |
|
||||||
|
|
||||||
|
## 8. Metadata Preservation
|
||||||
|
|
||||||
|
| Flag | Rsync Description | FastSync Status | Notes |
|
||||||
|
|------|-------------------|-----------------|-------|
|
||||||
|
| `-M`, `--preserve` | Preserve file metadata | ✅ Implemented | Mode, uid, gid, mtime |
|
||||||
|
| `-p`, `--perms` | Preserve permissions | 🔀 Alt Arg | `-p` means SSH port; permissions preserved via `-M`/`--preserve` |
|
||||||
|
| `-o`, `--owner` | Preserve owner | ✅ Implemented | Part of -M |
|
||||||
|
| `-g`, `--group` | Preserve group | ✅ Implemented | Part of -M |
|
||||||
|
| `-t`, `--times` | Preserve modification times | ✅ Implemented | Part of -M |
|
||||||
|
| `-E`, `--executability` | Preserve executability | ❌ Not Implemented | |
|
||||||
|
| `--chmod=CHMOD` | Affect file permissions | ❌ Not Implemented | |
|
||||||
|
| `-A`, `--acls` | Preserve ACLs | ⚠️ Partial | `preserve_acls` stored, not wired |
|
||||||
|
| `-X`, `--xattrs` | Preserve extended attributes | ⚠️ Partial | `preserve_xattrs` stored, not wired |
|
||||||
|
| `-H`, `--hard-links` | Preserve hard links | ⚠️ Partial | `preserve_hard_links` stored, not wired |
|
||||||
|
| `-D` | Same as --devices --specials | 🔀 Alt Arg | Maps to --devices only (no --specials) |
|
||||||
|
| `--devices` | Preserve device files | ⚠️ Partial | `preserve_devices` stored, not wired |
|
||||||
|
| `--specials` | Preserve special files | ❌ Not Implemented | |
|
||||||
|
| `--copy-devices` | Copy device contents as file | ❌ Not Implemented | |
|
||||||
|
| `--write-devices` | Write to devices as files | ❌ Not Implemented | |
|
||||||
|
| `-U`, `--atimes` | Preserve access times | ❌ Not Implemented | |
|
||||||
|
| `-N`, `--crtimes` | Preserve create times | ❌ Not Implemented | |
|
||||||
|
| `-O`, `--omit-dir-times` | Omit dirs from --times | ❌ Not Implemented | |
|
||||||
|
| `-J`, `--omit-link-times` | Omit symlinks from --times | ❌ Not Implemented | |
|
||||||
|
| `--super` | Receiver attempts super-user activities | ❌ Not Implemented | |
|
||||||
|
| `--fake-super` | Store/recover privileged attrs via xattrs | ❌ Not Implemented | |
|
||||||
|
|
||||||
|
## 9. Symlink Handling
|
||||||
|
|
||||||
|
| Flag | Rsync Description | FastSync Status | Notes |
|
||||||
|
|------|-------------------|-----------------|-------|
|
||||||
|
| `-l`, `--links` | Copy symlinks as symlinks | ⚠️ Partial | Scanner includes symlinks; target path not transmitted |
|
||||||
|
| `-L`, `--copy-links` | Transform symlink to referent | ✅ Implemented | `copy_links` config field |
|
||||||
|
| `--copy-unsafe-links` | Transform unsafe symlinks | ✅ Implemented | `copy_unsafe_links` config field |
|
||||||
|
| `--safe-links` | Ignore symlinks outside tree | ✅ Implemented | `safe_links` config field |
|
||||||
|
| `--munge-links` | Munge symlinks for safety | ❌ Not Implemented | |
|
||||||
|
| `-k`, `--copy-dirlinks` | Transform symlink to dir | ❌ Not Implemented | |
|
||||||
|
| `-K`, `--keep-dirlinks` | Treat symlinked dir as dir | ❌ Not Implemented | |
|
||||||
|
|
||||||
|
## 10. Sparse & Device
|
||||||
|
|
||||||
|
| Flag | Rsync Description | FastSync Status | Notes |
|
||||||
|
|------|-------------------|-----------------|-------|
|
||||||
|
| `-S`, `--sparse` | Sparse block handling | ✅ Implemented | `preserve_sparse` config field |
|
||||||
|
| `--preallocate` | Allocate dest files before writing | ❌ Not Implemented | |
|
||||||
|
|
||||||
|
## 11. Checksum & Comparison
|
||||||
|
|
||||||
|
| Flag | Rsync Description | FastSync Status | Notes |
|
||||||
|
|------|-------------------|-----------------|-------|
|
||||||
|
| `-c`, `--checksum` | Skip based on checksum | 🔀 Alt Arg | `-c` means compression; `--checksum` stored and forwarded to scanner |
|
||||||
|
| `--checksum-choice=STR` | Choose checksum algorithm | ❌ Not Implemented | xxHash used internally |
|
||||||
|
| `--compare-dest=DIR` | Compare dest files relative to DIR | ⚠️ Partial | `compare_dest` stored, not wired |
|
||||||
|
| `--copy-dest=DIR` | Include copies of unchanged files | ⚠️ Partial | `copy_dest` stored, not wired |
|
||||||
|
| `--link-dest=DIR` | Hardlink to files when unchanged | ⚠️ Partial | `link_dest` stored, not wired |
|
||||||
|
| `--fuzzy`, `--no-fuzzy` | Find similar file for basis | ❌ Not Implemented | |
|
||||||
|
|
||||||
|
## 12. Compression
|
||||||
|
|
||||||
|
| Flag | Rsync Description | FastSync Status | Notes |
|
||||||
|
|------|-------------------|-----------------|-------|
|
||||||
|
| `-z`, `--compress` | Compress file data | 🔀 Alt Arg | Always uses zstd (rsync supports multiple algorithms) |
|
||||||
|
| `--compress-choice=STR` | Choose compression algorithm | ⚠️ Partial | `compress_choice` stored, always zstd |
|
||||||
|
| `--compress-level=NUM` | Set compression level | ✅ Implemented | 1-22, default 5 |
|
||||||
|
| `--compress-threads=NUM` | Set compression threads | ❌ Not Implemented | |
|
||||||
|
| `--skip-compress=LIST` | Skip compress for suffixes | ❌ Not Implemented | Internal skip for hardcoded types; not user-configurable |
|
||||||
|
|
||||||
|
## 13. Connectivity
|
||||||
|
|
||||||
|
| Flag | Rsync Description | FastSync Status | Notes |
|
||||||
|
|------|-------------------|-----------------|-------|
|
||||||
|
| `-e`, `--rsh=COMMAND` | Remote shell to use | ✅ Implemented | SSH transport support |
|
||||||
|
| `--rsync-path=PROGRAM` | rsync binary on remote | ✅ Implemented | `rsync_path` config field |
|
||||||
|
| `--port=PORT` | Alternate daemon port | ✅ Implemented | `server_port` config field |
|
||||||
|
| `--sockopts=OPTIONS` | Custom TCP options | ❌ Not Implemented | |
|
||||||
|
| `--blocking-io` | Use blocking I/O for remote shell | ❌ Not Implemented | |
|
||||||
|
| `--outbuf=N\|L\|B` | Set output buffering | ❌ Not Implemented | |
|
||||||
|
| `--address=ADDRESS` | Bind address for outgoing socket | ✅ Implemented | `address` config field |
|
||||||
|
| `-4`, `--ipv4` | Prefer IPv4 | ✅ Implemented | `ipv4` config field |
|
||||||
|
| `-6`, `--ipv6` | Prefer IPv6 | ✅ Implemented | `ipv6` config field |
|
||||||
|
|
||||||
|
## 14. Daemon Mode
|
||||||
|
|
||||||
|
| Flag | Rsync Description | FastSync Status | Notes |
|
||||||
|
|------|-------------------|-----------------|-------|
|
||||||
|
| `--daemon` | Run as rsync daemon | ⚠️ Partial | `daemon` stored, not wired |
|
||||||
|
| `--config=FILE` | Alternate rsyncd.conf file | ⚠️ Partial | `daemon_config` stored, not wired |
|
||||||
|
| `--dparam=OVERRIDE` | Override global daemon config | ❌ Not Implemented | |
|
||||||
|
| `--no-detach` | Don't detach from parent | ❌ Not Implemented | |
|
||||||
|
| `--password-file=FILE` | Read daemon password from file | ❌ Not Implemented | |
|
||||||
|
| `--early-input=FILE` | Use FILE for daemon early exec | ❌ Not Implemented | |
|
||||||
|
|
||||||
|
## 15. Safety & Security
|
||||||
|
|
||||||
|
| Flag | Rsync Description | FastSync Status | Notes |
|
||||||
|
|------|-------------------|-----------------|-------|
|
||||||
|
| Path escape detection | Ensure files stay within root | ✅ Implemented | `has_path_traversal()` + realpath |
|
||||||
|
| Symlink-safe delete | Skip symlinks in delete walk | ✅ Implemented | `delete_extras_walk()` |
|
||||||
|
| Protocol version check | Verify compatible versions | ✅ Implemented | `config_receive()` |
|
||||||
|
| Max data/string/chunk sizes | Prevent OOM attacks | ✅ Implemented | Per-message limits |
|
||||||
|
| Per-connection memory limit | 1GB per connection | ✅ Implemented | `MAX_CONNECTION_MEMORY` |
|
||||||
|
| `--trust-sender` | Trust remote sender's file list | ❌ Not Implemented | |
|
||||||
|
| `--old-args` | Disable modern arg protection | ❌ Not Implemented | |
|
||||||
|
| `--ignore-missing-args` | Ignore missing source args | ❌ Not Implemented | |
|
||||||
|
| `--delete-missing-args` | Delete missing source args | ❌ Not Implemented | |
|
||||||
|
|
||||||
|
## 16. Batch Operations
|
||||||
|
|
||||||
|
| Flag | Rsync Description | FastSync Status | Notes |
|
||||||
|
|------|-------------------|-----------------|-------|
|
||||||
|
| `--write-batch=FILE` | Write batched update to file | ❌ Not Implemented | |
|
||||||
|
| `--only-write-batch=FILE` | Write batch without updating dest | ❌ Not Implemented | |
|
||||||
|
| `--read-batch=FILE` | Read batched update from file | ❌ Not Implemented | |
|
||||||
|
|
||||||
|
## 17. Advanced
|
||||||
|
|
||||||
|
| Flag | Rsync Description | FastSync Status | Notes |
|
||||||
|
|------|-------------------|-----------------|-------|
|
||||||
|
| `--stop-after=MINS` | Stop after N minutes | ❌ Not Implemented | |
|
||||||
|
| `--stop-at=TIME` | Stop at specified time | ❌ Not Implemented | |
|
||||||
|
| `--fsync` | Fsync every written file | ❌ Not Implemented | |
|
||||||
|
| `--protocol=NUM` | Force older protocol version | ❌ Not Implemented | |
|
||||||
|
| `--iconv=CONVERT_SPEC` | Charset conversion | ❌ Not Implemented | |
|
||||||
|
| `--checksum-seed=NUM` | Set checksum seed | ❌ Not Implemented | |
|
||||||
|
| `-s`, `--secluded-args` | Use protocol to send args | ❌ Not Implemented | |
|
||||||
|
| `--no-OPTION` | Turn off implied option | ❌ Not Implemented | |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## Recommendations: Top Features to Implement Next
|
||||||
|
|
||||||
|
Ranked by user demand, implementation complexity, and interoperability impact:
|
||||||
|
|
||||||
|
| Priority | Feature | Effort | Impact |
|
||||||
|
|----------|---------|--------|--------|
|
||||||
|
| 1 | `--whole-file` / `-W` | Low | High — users expect opt-out of delta |
|
||||||
|
| 2 | `--ignore-times` / `-I` | Low | Medium — useful for forcing re-transfer |
|
||||||
|
| 3 | `--size-only` | Low | Medium — common migration scenario |
|
||||||
|
| 4 | `--existing` / `--ignore-existing` | Low | Medium — common sync patterns |
|
||||||
|
| 5 | `--remove-source-files` | Low | High — common for moves/backup |
|
||||||
|
| 6 | `--delete-during` | Medium | High — performance improvement |
|
||||||
|
| 7 | `--delay-updates` | Medium | High — atomic updates |
|
||||||
|
| 8 | `--chmod` | Low | Medium — permission flexibility |
|
||||||
|
| 9 | `--executability` / `-E` | Low | Low — simple flag |
|
||||||
|
| 10 | `--skip-compress` | Low | Medium — performance tuning |
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
## FastSync-Specific Features (Not in rsync)
|
||||||
|
|
||||||
|
| Feature | Description |
|
||||||
|
|---------|-------------|
|
||||||
|
| `-m` | Multithreaded pipeline (scanner/loader/sender) |
|
||||||
|
| `-s` | Chunk serialization mode |
|
||||||
|
| `-f` / `--sendfile` | Zero-copy sendfile() syscall (TCP only) |
|
||||||
|
| `-c [level]` | zstd compression level (1-22) |
|
||||||
|
| `--chunk-size` | Configurable chunk size |
|
||||||
|
| `--queue-size` | Pipeline queue capacity |
|
||||||
|
| `--tls` | TLS encryption (mutual auth) |
|
||||||
|
| `--fastsync-server-path` | Path to fastsync-server binary |
|
||||||
|
| `--server-host` / `--server-port` | Direct TCP connection |
|
||||||
|
| Incremental sync | Skip unchanged files (size+mtime) |
|
||||||
|
| Delta transfer | Block-level delta for changed files |
|
||||||
+183
-114
@@ -12,6 +12,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#ifndef FASTSYNC_TEST_BUILD
|
||||||
/* Parse environment variables for source/destination directories and save-to-disk flag. */
|
/* Parse environment variables for source/destination directories and save-to-disk flag. */
|
||||||
static void parse_environment(const char** out_env_source, const char** out_env_dest,
|
static void parse_environment(const char** out_env_source, const char** out_env_dest,
|
||||||
bool* out_save_to_disk) {
|
bool* out_save_to_disk) {
|
||||||
@@ -22,6 +23,7 @@ static void parse_environment(const char** out_env_source, const char** out_env_
|
|||||||
if (env_save && (strcmp(env_save, "true") == 0 || strcmp(env_save, "1") == 0))
|
if (env_save && (strcmp(env_save, "true") == 0 || strcmp(env_save, "1") == 0))
|
||||||
*out_save_to_disk = true;
|
*out_save_to_disk = true;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/* Parse a string as a positive integer, returning true on success. */
|
/* Parse a string as a positive integer, returning true on success. */
|
||||||
static bool parse_positive_int(const char* s, int* out_val) {
|
static bool parse_positive_int(const char* s, int* out_val) {
|
||||||
@@ -49,16 +51,50 @@ static bool parse_nonneg_int(const char* s, int* out_val) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Duplicate a string argument into *dest, freeing the old value. Returns 0 on success, -1 on
|
||||||
|
* failure. */
|
||||||
|
static int set_string_option(char** dest, const char* value, const char* option_name) {
|
||||||
|
char* dup = str_dup(value);
|
||||||
|
if (!dup) {
|
||||||
|
fprintf(stderr, "Error: memory allocation failed for %s\n", option_name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
free(*dest);
|
||||||
|
*dest = dup;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Parse a string as a positive integer into *dest. Returns 0 on success, -1 on error. */
|
||||||
|
static int set_positive_int_option(int* dest, const char* value, const char* option_name) {
|
||||||
|
if (!parse_positive_int(value, dest)) {
|
||||||
|
fprintf(stderr, "Error: %s must be a positive integer\n", option_name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Parse a string as a non-negative integer into *dest. Returns 0 on success, -1 on error. */
|
||||||
|
static int set_nonneg_int_option(int* dest, const char* value, const char* option_name) {
|
||||||
|
if (!parse_nonneg_int(value, dest)) {
|
||||||
|
fprintf(stderr, "Error: %s must be a non-negative integer\n", option_name);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
static void print_usage(void);
|
static void print_usage(void);
|
||||||
static int read_patterns_from_file(const char* filepath, char*** patterns, int* count);
|
static int read_patterns_from_file(const char* filepath, char*** patterns, int* count);
|
||||||
|
|
||||||
/* Parse CLI arguments into config. Returns 0 on success, -1 on error, 1 for help/clean-exit. */
|
/* Parse CLI arguments into config. Returns 0 on success, -1 on error, 1 for help/clean-exit. */
|
||||||
static int parse_args(Config* config, int argc, char* argv[], int* positional_args,
|
int parse_args(Config* config, int argc, char* argv[], int* positional_args,
|
||||||
int* positional_count) {
|
int* positional_count) {
|
||||||
for (int i = 1; i < argc; i++) {
|
for (int i = 1; i < argc; i++) {
|
||||||
if (strcmp(argv[i], "--help") == 0) {
|
if (strcmp(argv[i], "--help") == 0) {
|
||||||
print_usage();
|
print_usage();
|
||||||
return 1;
|
return 1;
|
||||||
|
} else if (strcmp(argv[i], "-V") == 0 || strcmp(argv[i], "--version") == 0) {
|
||||||
|
printf("fastsync version %s\n", PROTOCOL_VERSION);
|
||||||
|
return 1;
|
||||||
} else if (strcmp(argv[i], "-a") == 0 || strcmp(argv[i], "--archive") == 0) {
|
} else if (strcmp(argv[i], "-a") == 0 || strcmp(argv[i], "--archive") == 0) {
|
||||||
config->use_compression = true;
|
config->use_compression = true;
|
||||||
config->use_multithreading = true;
|
config->use_multithreading = true;
|
||||||
@@ -71,6 +107,10 @@ static int parse_args(Config* config, int argc, char* argv[], int* positional_ar
|
|||||||
fprintf(stderr, "Error: invalid --port/-p value: %s\n", argv[i]);
|
fprintf(stderr, "Error: invalid --port/-p value: %s\n", argv[i]);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (config->ssh_port > 65535) {
|
||||||
|
fprintf(stderr, "Error: SSH port must be 1-65535\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
} else if (strcmp(argv[i], "--delete") == 0) {
|
} else if (strcmp(argv[i], "--delete") == 0) {
|
||||||
config->use_delete = true;
|
config->use_delete = true;
|
||||||
} else if (strcmp(argv[i], "--exclude") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--exclude") == 0 && i + 1 < argc) {
|
||||||
@@ -100,21 +140,47 @@ static int parse_args(Config* config, int argc, char* argv[], int* positional_ar
|
|||||||
}
|
}
|
||||||
config->include_patterns[config->include_count++] = dup;
|
config->include_patterns[config->include_count++] = dup;
|
||||||
} else if (strcmp(argv[i], "--max-size") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--max-size") == 0 && i + 1 < argc) {
|
||||||
config->max_size = strtoull(argv[++i], NULL, 10);
|
char* end;
|
||||||
|
errno = 0;
|
||||||
|
unsigned long long val = strtoull(argv[++i], &end, 10);
|
||||||
|
if (errno != 0 || *end != '\0') {
|
||||||
|
fprintf(stderr, "Error: --max-size must be a non-negative integer\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
config->max_size = val;
|
||||||
} else if (strcmp(argv[i], "--min-size") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--min-size") == 0 && i + 1 < argc) {
|
||||||
config->min_size = strtoull(argv[++i], NULL, 10);
|
char* end;
|
||||||
|
errno = 0;
|
||||||
|
unsigned long long val = strtoull(argv[++i], &end, 10);
|
||||||
|
if (errno != 0 || *end != '\0') {
|
||||||
|
fprintf(stderr, "Error: --min-size must be a non-negative integer\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
config->min_size = val;
|
||||||
} else if (strcmp(argv[i], "--incremental") == 0) {
|
} else if (strcmp(argv[i], "--incremental") == 0) {
|
||||||
config->use_incremental = true;
|
config->use_incremental = true;
|
||||||
} else if (strcmp(argv[i], "--delta") == 0) {
|
} else if (strcmp(argv[i], "--delta") == 0) {
|
||||||
config->use_delta = true;
|
config->use_delta = true;
|
||||||
} else if (strcmp(argv[i], "--delta-block") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--delta-block") == 0 && i + 1 < argc) {
|
||||||
unsigned long long val = strtoull(argv[++i], NULL, 10);
|
char* end;
|
||||||
|
errno = 0;
|
||||||
|
unsigned long long val = strtoull(argv[++i], &end, 10);
|
||||||
|
if (errno != 0 || *end != '\0') {
|
||||||
|
fprintf(stderr, "Error: --delta-block must be a positive integer\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
if (val >= DELTA_BLOCK_SIZE_MIN && val <= DELTA_BLOCK_SIZE_MAX)
|
if (val >= DELTA_BLOCK_SIZE_MIN && val <= DELTA_BLOCK_SIZE_MAX)
|
||||||
config->delta_block_size = (uint32_t)val;
|
config->delta_block_size = (uint32_t)val;
|
||||||
else
|
else
|
||||||
fprintf(stderr, "Warning: --delta-block value %llu out of range, using default\n", val);
|
fprintf(stderr, "Warning: --delta-block value %llu out of range, using default\n", val);
|
||||||
} else if (strcmp(argv[i], "--delta-max") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--delta-max") == 0 && i + 1 < argc) {
|
||||||
unsigned long long val = strtoull(argv[++i], NULL, 10);
|
char* end;
|
||||||
|
errno = 0;
|
||||||
|
unsigned long long val = strtoull(argv[++i], &end, 10);
|
||||||
|
if (errno != 0 || *end != '\0') {
|
||||||
|
fprintf(stderr, "Error: --delta-max must be a positive integer\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
if (val >= DELTA_MIN_FILE_SIZE)
|
if (val >= DELTA_MIN_FILE_SIZE)
|
||||||
config->delta_max_file_size = val;
|
config->delta_max_file_size = val;
|
||||||
else
|
else
|
||||||
@@ -126,27 +192,21 @@ static int parse_args(Config* config, int argc, char* argv[], int* positional_ar
|
|||||||
char* end_ptr;
|
char* end_ptr;
|
||||||
long level = strtol(argv[i + 1], &end_ptr, 10);
|
long level = strtol(argv[i + 1], &end_ptr, 10);
|
||||||
if (*end_ptr == '\0') {
|
if (*end_ptr == '\0') {
|
||||||
|
if (level < 1 || level > 22) {
|
||||||
|
fprintf(stderr, "Error: compression level must be 1-22\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
config->compression_level = (int)level;
|
config->compression_level = (int)level;
|
||||||
log_message(LOG_LEVEL_INFO, "Set Compression level to %ld", level);
|
log_message(LOG_LEVEL_INFO, "Set Compression level to %ld", level);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (strcmp(argv[i], "--source-dir") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--source-dir") == 0 && i + 1 < argc) {
|
||||||
char* dup = str_dup(argv[++i]);
|
if (set_string_option(&config->send_directory, argv[++i], "--source-dir") != 0)
|
||||||
if (!dup) {
|
|
||||||
fprintf(stderr, "Error: memory allocation failed for --source-dir\n");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
free(config->send_directory);
|
|
||||||
config->send_directory = dup;
|
|
||||||
} else if (strcmp(argv[i], "--dest-dir") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--dest-dir") == 0 && i + 1 < argc) {
|
||||||
char* dup = str_dup(argv[++i]);
|
if (set_string_option(&config->receive_root_directory, argv[++i], "--dest-dir") != 0)
|
||||||
if (!dup) {
|
|
||||||
fprintf(stderr, "Error: memory allocation failed for --dest-dir\n");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
free(config->receive_root_directory);
|
|
||||||
config->receive_root_directory = dup;
|
|
||||||
} else if (strcmp(argv[i], "--save-to-disk") == 0) {
|
} else if (strcmp(argv[i], "--save-to-disk") == 0) {
|
||||||
config->save_to_disk = true;
|
config->save_to_disk = true;
|
||||||
} else if (strcmp(argv[i], "-M") == 0 || strcmp(argv[i], "--preserve") == 0) {
|
} else if (strcmp(argv[i], "-M") == 0 || strcmp(argv[i], "--preserve") == 0) {
|
||||||
@@ -162,18 +222,17 @@ static int parse_args(Config* config, int argc, char* argv[], int* positional_ar
|
|||||||
config->use_chunk_serialization = true;
|
config->use_chunk_serialization = true;
|
||||||
log_message(LOG_LEVEL_INFO, "Enabled Chunk Serialization");
|
log_message(LOG_LEVEL_INFO, "Enabled Chunk Serialization");
|
||||||
} else if (strcmp(argv[i], "--server-host") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--server-host") == 0 && i + 1 < argc) {
|
||||||
char* dup = str_dup(argv[++i]);
|
if (set_string_option(&config->server_host, argv[++i], "--server-host") != 0)
|
||||||
if (!dup) {
|
|
||||||
fprintf(stderr, "Error: memory allocation failed for --server-host\n");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
free(config->server_host);
|
|
||||||
config->server_host = dup;
|
|
||||||
} else if (strcmp(argv[i], "--server-port") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--server-port") == 0 && i + 1 < argc) {
|
||||||
if (!parse_positive_int(argv[++i], &config->server_port)) {
|
if (!parse_positive_int(argv[++i], &config->server_port)) {
|
||||||
fprintf(stderr, "Error: invalid --server-port value: %s\n", argv[i]);
|
fprintf(stderr, "Error: invalid --server-port value: %s\n", argv[i]);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
if (config->server_port > 65535) {
|
||||||
|
fprintf(stderr, "Error: server port must be 1-65535\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
} else if (strcmp(argv[i], "--bwlimit") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--bwlimit") == 0 && i + 1 < argc) {
|
||||||
char* end;
|
char* end;
|
||||||
errno = 0;
|
errno = 0;
|
||||||
@@ -191,70 +250,50 @@ static int parse_args(Config* config, int argc, char* argv[], int* positional_ar
|
|||||||
} else if (strcmp(argv[i], "--progress") == 0) {
|
} else if (strcmp(argv[i], "--progress") == 0) {
|
||||||
config->show_progress = true;
|
config->show_progress = true;
|
||||||
} else if (strcmp(argv[i], "--chunk-size") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--chunk-size") == 0 && i + 1 < argc) {
|
||||||
unsigned long long val = strtoull(argv[++i], NULL, 10);
|
char* end;
|
||||||
if (val > 0)
|
errno = 0;
|
||||||
|
unsigned long long val = strtoull(argv[++i], &end, 10);
|
||||||
|
if (errno != 0 || *end != '\0' || val == 0) {
|
||||||
|
fprintf(stderr, "Error: --chunk-size must be a positive integer\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
config->chunk_size = val;
|
config->chunk_size = val;
|
||||||
} else if (strcmp(argv[i], "--tls") == 0) {
|
} else if (strcmp(argv[i], "--tls") == 0) {
|
||||||
config->use_tls = true;
|
config->use_tls = true;
|
||||||
} else if (strcmp(argv[i], "--cert") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--cert") == 0 && i + 1 < argc) {
|
||||||
char* dup = str_dup(argv[++i]);
|
if (set_string_option(&config->tls_cert, argv[++i], "--cert") != 0)
|
||||||
if (!dup) {
|
|
||||||
fprintf(stderr, "Error: memory allocation failed for --cert\n");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
free(config->tls_cert);
|
|
||||||
config->tls_cert = dup;
|
|
||||||
} else if (strcmp(argv[i], "--key") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--key") == 0 && i + 1 < argc) {
|
||||||
char* dup = str_dup(argv[++i]);
|
if (set_string_option(&config->tls_key, argv[++i], "--key") != 0)
|
||||||
if (!dup) {
|
|
||||||
fprintf(stderr, "Error: memory allocation failed for --key\n");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
free(config->tls_key);
|
|
||||||
config->tls_key = dup;
|
|
||||||
} else if (strcmp(argv[i], "--ca") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--ca") == 0 && i + 1 < argc) {
|
||||||
char* dup = str_dup(argv[++i]);
|
if (set_string_option(&config->tls_ca, argv[++i], "--ca") != 0)
|
||||||
if (!dup) {
|
|
||||||
fprintf(stderr, "Error: memory allocation failed for --ca\n");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
free(config->tls_ca);
|
|
||||||
config->tls_ca = dup;
|
|
||||||
} else if (strcmp(argv[i], "--timeout") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--timeout") == 0 && i + 1 < argc) {
|
||||||
int val;
|
if (set_positive_int_option(&config->timeout, argv[++i], "--timeout") != 0)
|
||||||
if (!parse_positive_int(argv[++i], &val)) {
|
|
||||||
fprintf(stderr, "Error: --timeout must be a positive integer\n");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
config->timeout = val;
|
|
||||||
} else if (strcmp(argv[i], "--contimeout") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--contimeout") == 0 && i + 1 < argc) {
|
||||||
int val;
|
if (set_positive_int_option(&config->contimeout, argv[++i], "--contimeout") != 0)
|
||||||
if (!parse_positive_int(argv[++i], &val)) {
|
|
||||||
fprintf(stderr, "Error: --contimeout must be a positive integer\n");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
config->contimeout = val;
|
|
||||||
} else if (strcmp(argv[i], "-q") == 0 || strcmp(argv[i], "--quiet") == 0 ||
|
} else if (strcmp(argv[i], "-q") == 0 || strcmp(argv[i], "--quiet") == 0 ||
|
||||||
strcmp(argv[i], "--silent") == 0) {
|
strcmp(argv[i], "--silent") == 0) {
|
||||||
config->quiet = true;
|
config->quiet = true;
|
||||||
} else if (strcmp(argv[i], "--backup") == 0) {
|
} else if (strcmp(argv[i], "--backup") == 0) {
|
||||||
config->backup = true;
|
config->backup = true;
|
||||||
} else if (strcmp(argv[i], "--backup-dir") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--backup-dir") == 0 && i + 1 < argc) {
|
||||||
char* dup = str_dup(argv[++i]);
|
if (set_string_option(&config->backup_dir, argv[++i], "--backup-dir") != 0)
|
||||||
if (!dup) {
|
|
||||||
fprintf(stderr, "Error: memory allocation failed for --backup-dir\n");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
free(config->backup_dir);
|
|
||||||
config->backup_dir = dup;
|
|
||||||
} else if (strcmp(argv[i], "--stats") == 0) {
|
} else if (strcmp(argv[i], "--stats") == 0) {
|
||||||
config->stats = true;
|
config->stats = true;
|
||||||
} else if (strcmp(argv[i], "--max-depth") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--max-depth") == 0 && i + 1 < argc) {
|
||||||
if (!parse_nonneg_int(argv[++i], &config->max_depth)) {
|
if (set_nonneg_int_option(&config->max_depth, argv[++i], "--max-depth") != 0)
|
||||||
fprintf(stderr, "Error: --max-depth must be a non-negative integer\n");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
} else if (strcmp(argv[i], "--log-file") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--log-file") == 0 && i + 1 < argc) {
|
||||||
|
if (config->log_file) {
|
||||||
|
fclose(config->log_file);
|
||||||
|
config->log_file = NULL;
|
||||||
|
log_set_file(NULL);
|
||||||
|
}
|
||||||
FILE* lf = fopen(argv[++i], "a");
|
FILE* lf = fopen(argv[++i], "a");
|
||||||
if (!lf) {
|
if (!lf) {
|
||||||
fprintf(stderr, "Error: could not open log file '%s': %s\n", argv[i], strerror(errno));
|
fprintf(stderr, "Error: could not open log file '%s': %s\n", argv[i], strerror(errno));
|
||||||
@@ -263,12 +302,8 @@ static int parse_args(Config* config, int argc, char* argv[], int* positional_ar
|
|||||||
config->log_file = lf;
|
config->log_file = lf;
|
||||||
log_set_file(lf);
|
log_set_file(lf);
|
||||||
} else if (strcmp(argv[i], "--queue-size") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--queue-size") == 0 && i + 1 < argc) {
|
||||||
int val;
|
if (set_positive_int_option(&config->queue_size, argv[++i], "--queue-size") != 0)
|
||||||
if (!parse_positive_int(argv[++i], &val)) {
|
|
||||||
fprintf(stderr, "Error: --queue-size must be a positive integer\n");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
config->queue_size = val;
|
|
||||||
} else if (strcmp(argv[i], "--exclude-from") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--exclude-from") == 0 && i + 1 < argc) {
|
||||||
if (read_patterns_from_file(argv[++i], &config->exclude_patterns, &config->exclude_count) !=
|
if (read_patterns_from_file(argv[++i], &config->exclude_patterns, &config->exclude_count) !=
|
||||||
0)
|
0)
|
||||||
@@ -280,13 +315,9 @@ static int parse_args(Config* config, int argc, char* argv[], int* positional_ar
|
|||||||
} else if (strcmp(argv[i], "--partial") == 0) {
|
} else if (strcmp(argv[i], "--partial") == 0) {
|
||||||
config->partial = true;
|
config->partial = true;
|
||||||
} else if (strcmp(argv[i], "--fastsync-server-path") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--fastsync-server-path") == 0 && i + 1 < argc) {
|
||||||
char* dup = str_dup(argv[++i]);
|
if (set_string_option(&config->fastsync_server_path, argv[++i], "--fastsync-server-path") !=
|
||||||
if (!dup) {
|
0)
|
||||||
fprintf(stderr, "Error: memory allocation failed for --fastsync-server-path\n");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
free(config->fastsync_server_path);
|
|
||||||
config->fastsync_server_path = dup;
|
|
||||||
} else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) {
|
} else if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--verbose") == 0) {
|
||||||
set_log_level(LOG_LEVEL_DEBUG);
|
set_log_level(LOG_LEVEL_DEBUG);
|
||||||
} else if (strcmp(argv[i], "-l") == 0 || strcmp(argv[i], "--links") == 0) {
|
} else if (strcmp(argv[i], "-l") == 0 || strcmp(argv[i], "--links") == 0) {
|
||||||
@@ -310,15 +341,14 @@ static int parse_args(Config* config, int argc, char* argv[], int* positional_ar
|
|||||||
} else if (strcmp(argv[i], "-i") == 0 || strcmp(argv[i], "--itemize-changes") == 0) {
|
} else if (strcmp(argv[i], "-i") == 0 || strcmp(argv[i], "--itemize-changes") == 0) {
|
||||||
config->itemize_changes = true;
|
config->itemize_changes = true;
|
||||||
} else if (strcmp(argv[i], "--out-format") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--out-format") == 0 && i + 1 < argc) {
|
||||||
char* dup = str_dup(argv[++i]);
|
if (set_string_option(&config->out_format, argv[++i], "--out-format") != 0)
|
||||||
if (!dup)
|
|
||||||
return -1;
|
return -1;
|
||||||
free(config->out_format);
|
|
||||||
config->out_format = dup;
|
|
||||||
} else if (strcmp(argv[i], "--info") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--info") == 0 && i + 1 < argc) {
|
||||||
config->info_level = atoi(argv[++i]);
|
if (set_nonneg_int_option(&config->info_level, argv[++i], "--info") != 0)
|
||||||
|
return -1;
|
||||||
} else if (strcmp(argv[i], "--debug") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--debug") == 0 && i + 1 < argc) {
|
||||||
config->debug_level = atoi(argv[++i]);
|
if (set_nonneg_int_option(&config->debug_level, argv[++i], "--debug") != 0)
|
||||||
|
return -1;
|
||||||
} else if (strcmp(argv[i], "--list-only") == 0) {
|
} else if (strcmp(argv[i], "--list-only") == 0) {
|
||||||
config->list_only = true;
|
config->list_only = true;
|
||||||
} else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--human-readable") == 0) {
|
} else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--human-readable") == 0) {
|
||||||
@@ -336,12 +366,8 @@ static int parse_args(Config* config, int argc, char* argv[], int* positional_ar
|
|||||||
} else if (strcmp(argv[i], "--delete-after") == 0) {
|
} else if (strcmp(argv[i], "--delete-after") == 0) {
|
||||||
config->delete_after = true;
|
config->delete_after = true;
|
||||||
} else if (strcmp(argv[i], "--max-delete") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--max-delete") == 0 && i + 1 < argc) {
|
||||||
int val;
|
if (set_nonneg_int_option(&config->max_delete, argv[++i], "--max-delete") != 0)
|
||||||
if (!parse_nonneg_int(argv[++i], &val)) {
|
|
||||||
fprintf(stderr, "Error: --max-delete must be a non-negative integer\n");
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
|
||||||
config->max_delete = val;
|
|
||||||
} else if (strcmp(argv[i], "--filter") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--filter") == 0 && i + 1 < argc) {
|
||||||
if (!config->filters)
|
if (!config->filters)
|
||||||
config->filters = array_list_create(free);
|
config->filters = array_list_create(free);
|
||||||
@@ -350,11 +376,8 @@ static int parse_args(Config* config, int argc, char* argv[], int* positional_ar
|
|||||||
return -1;
|
return -1;
|
||||||
array_list_add(config->filters, dup);
|
array_list_add(config->filters, dup);
|
||||||
} else if (strcmp(argv[i], "--files-from") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--files-from") == 0 && i + 1 < argc) {
|
||||||
char* dup = str_dup(argv[++i]);
|
if (set_string_option(&config->files_from, argv[++i], "--files-from") != 0)
|
||||||
if (!dup)
|
|
||||||
return -1;
|
return -1;
|
||||||
free(config->files_from);
|
|
||||||
config->files_from = dup;
|
|
||||||
} else if (strcmp(argv[i], "--cvs-exclude") == 0) {
|
} else if (strcmp(argv[i], "--cvs-exclude") == 0) {
|
||||||
config->cvs_exclude = true;
|
config->cvs_exclude = true;
|
||||||
} else if (strcmp(argv[i], "--prune-empty-dirs") == 0) {
|
} else if (strcmp(argv[i], "--prune-empty-dirs") == 0) {
|
||||||
@@ -363,45 +386,67 @@ static int parse_args(Config* config, int argc, char* argv[], int* positional_ar
|
|||||||
config->relative = true;
|
config->relative = true;
|
||||||
} else if (strcmp(argv[i], "-e") == 0 || strcmp(argv[i], "--rsh") == 0) {
|
} else if (strcmp(argv[i], "-e") == 0 || strcmp(argv[i], "--rsh") == 0) {
|
||||||
if (i + 1 < argc) {
|
if (i + 1 < argc) {
|
||||||
char* dup = str_dup(argv[++i]);
|
if (set_string_option(&config->rsh_command, argv[++i], "-e/--rsh") != 0)
|
||||||
if (!dup)
|
|
||||||
return -1;
|
return -1;
|
||||||
free(config->rsh_command);
|
|
||||||
config->rsh_command = dup;
|
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, "Error: -e/--rsh requires a command argument\n");
|
fprintf(stderr, "Error: -e/--rsh requires a command argument\n");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else if (strcmp(argv[i], "--rsync-path") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--rsync-path") == 0 && i + 1 < argc) {
|
||||||
char* dup = str_dup(argv[++i]);
|
if (set_string_option(&config->rsync_path, argv[++i], "--rsync-path") != 0)
|
||||||
if (!dup)
|
|
||||||
return -1;
|
return -1;
|
||||||
free(config->rsync_path);
|
|
||||||
config->rsync_path = dup;
|
|
||||||
} else if (strcmp(argv[i], "--temp-dir") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--temp-dir") == 0 && i + 1 < argc) {
|
||||||
char* dup = str_dup(argv[++i]);
|
if (set_string_option(&config->temp_dir, argv[++i], "--temp-dir") != 0)
|
||||||
if (!dup)
|
|
||||||
return -1;
|
return -1;
|
||||||
free(config->temp_dir);
|
|
||||||
config->temp_dir = dup;
|
|
||||||
} else if (strcmp(argv[i], "--compare-dest") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--compare-dest") == 0 && i + 1 < argc) {
|
||||||
char* dup = str_dup(argv[++i]);
|
if (set_string_option(&config->compare_dest, argv[++i], "--compare-dest") != 0)
|
||||||
if (!dup)
|
|
||||||
return -1;
|
return -1;
|
||||||
free(config->compare_dest);
|
|
||||||
config->compare_dest = dup;
|
|
||||||
} else if (strcmp(argv[i], "--copy-dest") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--copy-dest") == 0 && i + 1 < argc) {
|
||||||
char* dup = str_dup(argv[++i]);
|
if (set_string_option(&config->copy_dest, argv[++i], "--copy-dest") != 0)
|
||||||
if (!dup)
|
|
||||||
return -1;
|
return -1;
|
||||||
free(config->copy_dest);
|
|
||||||
config->copy_dest = dup;
|
|
||||||
} else if (strcmp(argv[i], "--link-dest") == 0 && i + 1 < argc) {
|
} else if (strcmp(argv[i], "--link-dest") == 0 && i + 1 < argc) {
|
||||||
char* dup = str_dup(argv[++i]);
|
if (set_string_option(&config->link_dest, argv[++i], "--link-dest") != 0)
|
||||||
if (!dup)
|
|
||||||
return -1;
|
return -1;
|
||||||
free(config->link_dest);
|
} else if (strcmp(argv[i], "--partial-dir") == 0 && i + 1 < argc) {
|
||||||
config->link_dest = dup;
|
if (set_string_option(&config->partial_dir, argv[++i], "--partial-dir") != 0)
|
||||||
|
return -1;
|
||||||
|
} else if (strcmp(argv[i], "--suffix") == 0 && i + 1 < argc) {
|
||||||
|
if (set_string_option(&config->suffix, argv[++i], "--suffix") != 0)
|
||||||
|
return -1;
|
||||||
|
} else if (strcmp(argv[i], "--delete-before") == 0) {
|
||||||
|
config->delete_before = true;
|
||||||
|
} else if (strcmp(argv[i], "-T") == 0 && i + 1 < argc) {
|
||||||
|
if (set_positive_int_option(&config->timeout, argv[++i], "-T") != 0)
|
||||||
|
return -1;
|
||||||
|
} else if (strcmp(argv[i], "--address") == 0 && i + 1 < argc) {
|
||||||
|
if (set_string_option(&config->address, argv[++i], "--address") != 0)
|
||||||
|
return -1;
|
||||||
|
} else if (strcmp(argv[i], "--bind-address") == 0 && i + 1 < argc) {
|
||||||
|
if (set_string_option(&config->bind_address, argv[++i], "--bind-address") != 0)
|
||||||
|
return -1;
|
||||||
|
} else if (strcmp(argv[i], "--ipv6") == 0) {
|
||||||
|
config->ipv6 = true;
|
||||||
|
} else if (strcmp(argv[i], "--ipv4") == 0) {
|
||||||
|
config->ipv4 = true;
|
||||||
|
} else if (strcmp(argv[i], "--daemon") == 0) {
|
||||||
|
config->daemon = true;
|
||||||
|
} else if (strcmp(argv[i], "--config") == 0 && i + 1 < argc) {
|
||||||
|
if (set_string_option(&config->daemon_config, argv[++i], "--config") != 0)
|
||||||
|
return -1;
|
||||||
|
} else if (strcmp(argv[i], "--server") == 0) {
|
||||||
|
config->server_mode = true;
|
||||||
|
} else if (strcmp(argv[i], "--checksum") == 0) {
|
||||||
|
config->checksum = true;
|
||||||
|
} else if (strcmp(argv[i], "--compress-choice") == 0 && i + 1 < argc) {
|
||||||
|
if (set_string_option(&config->compress_choice, argv[++i], "--compress-choice") != 0)
|
||||||
|
return -1;
|
||||||
|
} else if (strcmp(argv[i], "--compress-level") == 0 && i + 1 < argc) {
|
||||||
|
if (set_positive_int_option(&config->compression_level, argv[++i], "--compress-level") != 0)
|
||||||
|
return -1;
|
||||||
|
if (config->compression_level < 1 || config->compression_level > 22) {
|
||||||
|
fprintf(stderr, "Error: --compress-level must be between 1 and 22\n");
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
} else if (argv[i][0] == '-') {
|
} else if (argv[i][0] == '-') {
|
||||||
fprintf(stderr, "Unknown option: %s\n", argv[i]);
|
fprintf(stderr, "Unknown option: %s\n", argv[i]);
|
||||||
print_usage();
|
print_usage();
|
||||||
@@ -419,6 +464,7 @@ static int parse_args(Config* config, int argc, char* argv[], int* positional_ar
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef FASTSYNC_TEST_BUILD
|
||||||
/* Validate config after parsing. Returns true if valid. */
|
/* Validate config after parsing. Returns true if valid. */
|
||||||
static bool validate_config(const Config* config) {
|
static bool validate_config(const Config* config) {
|
||||||
if (!config->send_directory || !config->receive_root_directory) {
|
if (!config->send_directory || !config->receive_root_directory) {
|
||||||
@@ -459,6 +505,7 @@ static bool validate_config(const Config* config) {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
#endif /* FASTSYNC_TEST_BUILD */
|
||||||
|
|
||||||
static void print_usage(void) {
|
static void print_usage(void) {
|
||||||
printf("Usage:\n");
|
printf("Usage:\n");
|
||||||
@@ -507,16 +554,23 @@ static void print_usage(void) {
|
|||||||
printf(" --key <path> TLS private key file (PEM)\n");
|
printf(" --key <path> TLS private key file (PEM)\n");
|
||||||
printf(" --ca <path> TLS CA certificate file (PEM)\n");
|
printf(" --ca <path> TLS CA certificate file (PEM)\n");
|
||||||
printf(" --timeout <sec> I/O timeout in seconds (default: 30)\n");
|
printf(" --timeout <sec> I/O timeout in seconds (default: 30)\n");
|
||||||
|
printf(" -T <sec> Alias for --timeout\n");
|
||||||
printf(" --contimeout <sec> Connection timeout in seconds (default: 10)\n");
|
printf(" --contimeout <sec> Connection timeout in seconds (default: 10)\n");
|
||||||
|
printf(" --address <host> Server hostname/IP to connect to\n");
|
||||||
|
printf(" --bind-address <ip> Bind to specific local address\n");
|
||||||
|
printf(" --ipv6 Prefer IPv6 connections\n");
|
||||||
|
printf(" --ipv4 Prefer IPv4 connections\n");
|
||||||
printf(" -q, --quiet Suppress non-error output\n");
|
printf(" -q, --quiet Suppress non-error output\n");
|
||||||
printf(" --silent Alias for --quiet\n");
|
printf(" --silent Alias for --quiet\n");
|
||||||
printf(" --backup Backup existing files before overwriting\n");
|
printf(" --backup Backup existing files before overwriting\n");
|
||||||
printf(" --backup-dir <dir> Directory for backups (requires --backup)\n");
|
printf(" --backup-dir <dir> Directory for backups (requires --backup)\n");
|
||||||
|
printf(" --suffix <str> Backup suffix (default: ~)\n");
|
||||||
printf(" --stats Print transfer statistics at end\n");
|
printf(" --stats Print transfer statistics at end\n");
|
||||||
printf(" --max-depth <n> Maximum directory depth (0=unlimited)\n");
|
printf(" --max-depth <n> Maximum directory depth (0=unlimited)\n");
|
||||||
printf(" --log-file <path> Write log messages to file\n");
|
printf(" --log-file <path> Write log messages to file\n");
|
||||||
printf(" --queue-size <n> Queue capacity for multithreaded mode (default: 100)\n");
|
printf(" --queue-size <n> Queue capacity for multithreaded mode (default: 100)\n");
|
||||||
printf(" --partial Keep partial files on interrupted transfer\n");
|
printf(" --partial Keep partial files on interrupted transfer\n");
|
||||||
|
printf(" --partial-dir <dir> Directory for partial files\n");
|
||||||
printf(" --fastsync-server-path <path>\n");
|
printf(" --fastsync-server-path <path>\n");
|
||||||
printf(" Path to fastsync-server on remote (default: fastsync-server)\n");
|
printf(" Path to fastsync-server on remote (default: fastsync-server)\n");
|
||||||
printf(" -l, --links Copy symlinks as symlinks\n");
|
printf(" -l, --links Copy symlinks as symlinks\n");
|
||||||
@@ -538,6 +592,7 @@ static void print_usage(void) {
|
|||||||
printf(" --inplace Update files in-place (no temp+rename)\n");
|
printf(" --inplace Update files in-place (no temp+rename)\n");
|
||||||
printf(" --append Append data to shorter files\n");
|
printf(" --append Append data to shorter files\n");
|
||||||
printf(" --append-verify Append with verify\n");
|
printf(" --append-verify Append with verify\n");
|
||||||
|
printf(" --delete-before Delete before transfer\n");
|
||||||
printf(" --delete-excluded Also delete excluded files\n");
|
printf(" --delete-excluded Also delete excluded files\n");
|
||||||
printf(" --delete-after Delete after transfer, not before\n");
|
printf(" --delete-after Delete after transfer, not before\n");
|
||||||
printf(" --max-delete <n> Maximum number of files to delete\n");
|
printf(" --max-delete <n> Maximum number of files to delete\n");
|
||||||
@@ -548,11 +603,18 @@ static void print_usage(void) {
|
|||||||
printf(" -R, --relative Use relative paths\n");
|
printf(" -R, --relative Use relative paths\n");
|
||||||
printf(" -e, --rsh <cmd> Specify remote shell\n");
|
printf(" -e, --rsh <cmd> Specify remote shell\n");
|
||||||
printf(" --rsync-path <path> Path to remote binary\n");
|
printf(" --rsync-path <path> Path to remote binary\n");
|
||||||
|
printf(" --daemon Run in daemon mode\n");
|
||||||
|
printf(" --config <path> Path to configuration file\n");
|
||||||
|
printf(" --server Run in server mode\n");
|
||||||
|
printf(" --checksum Skip files based on checksum, not mod-time/size\n");
|
||||||
|
printf(" --compress-choice <alg> Compression algorithm (default: zstd)\n");
|
||||||
|
printf(" --compress-level <n> Compression level (default: 5)\n");
|
||||||
printf(" --temp-dir <dir> Temporary directory for files\n");
|
printf(" --temp-dir <dir> Temporary directory for files\n");
|
||||||
printf(" --compare-dest <dir> Compare destination\n");
|
printf(" --compare-dest <dir> Compare destination\n");
|
||||||
printf(" --copy-dest <dir> Copy destination\n");
|
printf(" --copy-dest <dir> Copy destination\n");
|
||||||
printf(" --link-dest <dir> Link destination\n");
|
printf(" --link-dest <dir> Link destination\n");
|
||||||
printf(" --help Show this help\n");
|
printf(" --help Show this help\n");
|
||||||
|
printf(" -V, --version Show version\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
static int read_patterns_from_file(const char* filepath, char*** patterns, int* count) {
|
static int read_patterns_from_file(const char* filepath, char*** patterns, int* count) {
|
||||||
@@ -561,8 +623,10 @@ static int read_patterns_from_file(const char* filepath, char*** patterns, int*
|
|||||||
fprintf(stderr, "Error: could not open pattern file '%s': %s\n", filepath, strerror(errno));
|
fprintf(stderr, "Error: could not open pattern file '%s': %s\n", filepath, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
char line[4096];
|
char* line = NULL;
|
||||||
while (fgets(line, sizeof(line), fp)) {
|
size_t line_size = 0;
|
||||||
|
ssize_t n;
|
||||||
|
while ((n = getline(&line, &line_size, fp)) != -1) {
|
||||||
char* p = line;
|
char* p = line;
|
||||||
while (*p == ' ' || *p == '\t')
|
while (*p == ' ' || *p == '\t')
|
||||||
p++;
|
p++;
|
||||||
@@ -576,6 +640,7 @@ static int read_patterns_from_file(const char* filepath, char*** patterns, int*
|
|||||||
char** tmp = realloc(*patterns, (*count + 1) * sizeof(char*));
|
char** tmp = realloc(*patterns, (*count + 1) * sizeof(char*));
|
||||||
if (!tmp) {
|
if (!tmp) {
|
||||||
fprintf(stderr, "Error: memory allocation failed for pattern file\n");
|
fprintf(stderr, "Error: memory allocation failed for pattern file\n");
|
||||||
|
free(line);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@@ -583,15 +648,18 @@ static int read_patterns_from_file(const char* filepath, char*** patterns, int*
|
|||||||
char* dup = str_dup(p);
|
char* dup = str_dup(p);
|
||||||
if (!dup) {
|
if (!dup) {
|
||||||
fprintf(stderr, "Error: memory allocation failed for pattern file\n");
|
fprintf(stderr, "Error: memory allocation failed for pattern file\n");
|
||||||
|
free(line);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
(*patterns)[(*count)++] = dup;
|
(*patterns)[(*count)++] = dup;
|
||||||
}
|
}
|
||||||
|
free(line);
|
||||||
fclose(fp);
|
fclose(fp);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef FASTSYNC_TEST_BUILD
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
const char* env_source = NULL;
|
const char* env_source = NULL;
|
||||||
const char* env_dest = NULL;
|
const char* env_dest = NULL;
|
||||||
@@ -697,3 +765,4 @@ cleanup:
|
|||||||
}
|
}
|
||||||
return exit_code;
|
return exit_code;
|
||||||
}
|
}
|
||||||
|
#endif /* FASTSYNC_TEST_BUILD */
|
||||||
|
|||||||
+175
-17
@@ -25,13 +25,16 @@
|
|||||||
|
|
||||||
#define STREAM_THRESHOLD (64ULL * 1024 * 1024)
|
#define STREAM_THRESHOLD (64ULL * 1024 * 1024)
|
||||||
|
|
||||||
|
/* Forward declaration for progress-reporting thread used in multithreaded send. */
|
||||||
|
static int progress_thread_fn(void* arg);
|
||||||
|
|
||||||
/* Print dry-run manifest showing files that would be transferred. Returns 0 on success. */
|
/* Print dry-run manifest showing files that would be transferred. Returns 0 on success. */
|
||||||
static int send_dry_run_manifest(Config* config) {
|
static int send_dry_run_manifest(Config* config) {
|
||||||
DirectoryScanner* scanner = directory_scanner_create(
|
DirectoryScanner* scanner = directory_scanner_create(
|
||||||
config->send_directory, config->use_metadata, config->chunk_size, config->exclude_patterns,
|
config->send_directory, config->use_metadata, config->chunk_size, config->exclude_patterns,
|
||||||
config->exclude_count, config->include_patterns, config->include_count, config->max_size,
|
config->exclude_count, config->include_patterns, config->include_count, config->max_size,
|
||||||
config->min_size, config->max_depth, config->follow_symlinks, config->copy_links,
|
config->min_size, config->max_depth, config->follow_symlinks, config->copy_links,
|
||||||
config->safe_links, config->copy_unsafe_links);
|
config->safe_links, config->copy_unsafe_links, config->checksum);
|
||||||
if (!scanner)
|
if (!scanner)
|
||||||
return -1;
|
return -1;
|
||||||
Chunk* chunk;
|
Chunk* chunk;
|
||||||
@@ -271,6 +274,9 @@ static int send_chunks_multithreaded(void* pipeline_context) {
|
|||||||
if (context->config->transport == TRANSPORT_SSH) {
|
if (context->config->transport == TRANSPORT_SSH) {
|
||||||
if (context->config->use_sendfile) {
|
if (context->config->use_sendfile) {
|
||||||
fprintf(stderr, "Error: -f/--sendfile is not supported with SSH transport\n");
|
fprintf(stderr, "Error: -f/--sendfile is not supported with SSH transport\n");
|
||||||
|
mtx_lock(&context->mutex_progress);
|
||||||
|
context->sender_done = true;
|
||||||
|
mtx_unlock(&context->mutex_progress);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
client = client_connect_ssh(context->config->ssh_destination, context->config->ssh_port,
|
client = client_connect_ssh(context->config->ssh_destination, context->config->ssh_port,
|
||||||
@@ -283,6 +289,9 @@ static int send_chunks_multithreaded(void* pipeline_context) {
|
|||||||
if (client)
|
if (client)
|
||||||
client_delete(client);
|
client_delete(client);
|
||||||
fprintf(stderr, "Error: could not connect to server via TLS\n");
|
fprintf(stderr, "Error: could not connect to server via TLS\n");
|
||||||
|
mtx_lock(&context->mutex_progress);
|
||||||
|
context->sender_done = true;
|
||||||
|
mtx_unlock(&context->mutex_progress);
|
||||||
return thrd_error;
|
return thrd_error;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -292,12 +301,18 @@ static int send_chunks_multithreaded(void* pipeline_context) {
|
|||||||
if (client)
|
if (client)
|
||||||
client_delete(client);
|
client_delete(client);
|
||||||
fprintf(stderr, "Error: could not connect to server\n");
|
fprintf(stderr, "Error: could not connect to server\n");
|
||||||
|
mtx_lock(&context->mutex_progress);
|
||||||
|
context->sender_done = true;
|
||||||
|
mtx_unlock(&context->mutex_progress);
|
||||||
return thrd_error;
|
return thrd_error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!config_send(client->file_descriptor, context->config)) {
|
if (!config_send(client->file_descriptor, context->config)) {
|
||||||
client_disconnect(client);
|
client_disconnect(client);
|
||||||
client_delete(client);
|
client_delete(client);
|
||||||
|
mtx_lock(&context->mutex_progress);
|
||||||
|
context->sender_done = true;
|
||||||
|
mtx_unlock(&context->mutex_progress);
|
||||||
return thrd_error;
|
return thrd_error;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -316,19 +331,39 @@ static int send_chunks_multithreaded(void* pipeline_context) {
|
|||||||
int ok = receive_status(client->file_descriptor, &s) && s == STATUS_OK;
|
int ok = receive_status(client->file_descriptor, &s) && s == STATUS_OK;
|
||||||
client_disconnect(client);
|
client_disconnect(client);
|
||||||
client_delete(client);
|
client_delete(client);
|
||||||
|
mtx_lock(&context->mutex_progress);
|
||||||
|
context->sender_done = true;
|
||||||
|
mtx_unlock(&context->mutex_progress);
|
||||||
return ok ? thrd_success : thrd_error;
|
return ok ? thrd_success : thrd_error;
|
||||||
|
|
||||||
send_fail:
|
send_fail:
|
||||||
client_disconnect(client);
|
client_disconnect(client);
|
||||||
client_delete(client);
|
client_delete(client);
|
||||||
|
mtx_lock(&context->mutex_progress);
|
||||||
|
context->sender_done = true;
|
||||||
|
mtx_unlock(&context->mutex_progress);
|
||||||
return thrd_error;
|
return thrd_error;
|
||||||
}
|
}
|
||||||
if (send_chunk(client, current_chunk, context->config) != 0) {
|
if (send_chunk(client, current_chunk, context->config) != 0) {
|
||||||
fprintf(stderr, "Error: unexpected error while sending chunk\n");
|
fprintf(stderr, "Error: unexpected error while sending chunk\n");
|
||||||
|
chunk_destroy(current_chunk);
|
||||||
client_disconnect(client);
|
client_disconnect(client);
|
||||||
client_delete(client);
|
client_delete(client);
|
||||||
|
mtx_lock(&context->mutex_progress);
|
||||||
|
context->sender_done = true;
|
||||||
|
mtx_unlock(&context->mutex_progress);
|
||||||
return thrd_error;
|
return thrd_error;
|
||||||
}
|
}
|
||||||
|
if (context->config->show_progress) {
|
||||||
|
unsigned long long chunk_bytes = 0;
|
||||||
|
for (int i = 0; i < current_chunk->element_count; i++) {
|
||||||
|
if (current_chunk->items[i] && current_chunk->items[i]->data)
|
||||||
|
chunk_bytes += current_chunk->items[i]->data->size;
|
||||||
|
}
|
||||||
|
mtx_lock(&context->mutex_progress);
|
||||||
|
context->progress_bytes += chunk_bytes;
|
||||||
|
mtx_unlock(&context->mutex_progress);
|
||||||
|
}
|
||||||
chunk_destroy(current_chunk);
|
chunk_destroy(current_chunk);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -340,7 +375,8 @@ static int scan_directory_multithreaded(void* pipeline_context) {
|
|||||||
context->config->exclude_patterns, context->config->exclude_count,
|
context->config->exclude_patterns, context->config->exclude_count,
|
||||||
context->config->include_patterns, context->config->include_count, context->config->max_size,
|
context->config->include_patterns, context->config->include_count, context->config->max_size,
|
||||||
context->config->min_size, context->config->max_depth, 4, context->config->follow_symlinks,
|
context->config->min_size, context->config->max_depth, 4, context->config->follow_symlinks,
|
||||||
context->config->copy_links, context->config->safe_links, context->config->copy_unsafe_links);
|
context->config->copy_links, context->config->safe_links, context->config->copy_unsafe_links,
|
||||||
|
context->config->checksum);
|
||||||
|
|
||||||
Chunk* current_chunk;
|
Chunk* current_chunk;
|
||||||
while ((current_chunk = parallel_scanner_next(scanner)) != NULL) {
|
while ((current_chunk = parallel_scanner_next(scanner)) != NULL) {
|
||||||
@@ -350,13 +386,31 @@ static int scan_directory_multithreaded(void* pipeline_context) {
|
|||||||
const char* p = current_chunk->items[i]->path;
|
const char* p = current_chunk->items[i]->path;
|
||||||
if (*p == '/')
|
if (*p == '/')
|
||||||
p++;
|
p++;
|
||||||
array_list_add(context->manifest, str_dup(p));
|
char* manifest_entry = str_dup(p);
|
||||||
|
if (!manifest_entry) {
|
||||||
|
log_message(LOG_LEVEL_ERROR, "Failed to allocate manifest entry");
|
||||||
|
mtx_unlock(&context->mutex_scanner);
|
||||||
|
context->cancelled = true;
|
||||||
|
cnd_broadcast(&context->condition_not_full_scanner);
|
||||||
|
cnd_broadcast(&context->condition_not_empty_scanner);
|
||||||
|
parallel_scanner_destroy(scanner);
|
||||||
|
return thrd_error;
|
||||||
|
}
|
||||||
|
array_list_add(context->manifest, manifest_entry);
|
||||||
}
|
}
|
||||||
mtx_unlock(&context->mutex_scanner);
|
mtx_unlock(&context->mutex_scanner);
|
||||||
}
|
}
|
||||||
queue_enqueue_multithreaded(context->queue_scanner, current_chunk, &context->mutex_scanner,
|
if (!queue_enqueue_multithreaded_cancel(
|
||||||
&context->condition_not_empty_scanner,
|
context->queue_scanner, current_chunk, &context->mutex_scanner,
|
||||||
&context->condition_not_full_scanner);
|
&context->condition_not_empty_scanner, &context->condition_not_full_scanner,
|
||||||
|
&context->cancelled)) {
|
||||||
|
chunk_destroy(current_chunk);
|
||||||
|
context->cancelled = true;
|
||||||
|
cnd_broadcast(&context->condition_not_full_scanner);
|
||||||
|
cnd_broadcast(&context->condition_not_empty_scanner);
|
||||||
|
parallel_scanner_destroy(scanner);
|
||||||
|
return thrd_error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
mtx_lock(&context->mutex_scanner);
|
mtx_lock(&context->mutex_scanner);
|
||||||
context->scanner_done = true;
|
context->scanner_done = true;
|
||||||
@@ -392,11 +446,54 @@ static int load_files_multithreaded(void* pipeline_context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
queue_enqueue_multithreaded(context->queue_loader, chunk, &context->mutex_loader,
|
if (!queue_enqueue_multithreaded_cancel(context->queue_loader, chunk, &context->mutex_loader,
|
||||||
&context->condition_not_empty_loader,
|
&context->condition_not_empty_loader,
|
||||||
&context->condition_not_full_loader);
|
&context->condition_not_full_loader,
|
||||||
|
&context->cancelled)) {
|
||||||
|
chunk_destroy(chunk);
|
||||||
|
context->cancelled = true;
|
||||||
|
cnd_broadcast(&context->condition_not_full_loader);
|
||||||
|
cnd_broadcast(&context->condition_not_empty_loader);
|
||||||
|
return thrd_error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Progress-reporting thread for multithreaded send. Runs in parallel with
|
||||||
|
the scanner/loader/sender threads and prints periodic progress to stderr. */
|
||||||
|
static int progress_thread_fn(void* arg) {
|
||||||
|
PipelineContextSender* context = (PipelineContextSender*)arg;
|
||||||
|
time_t last_progress = 0;
|
||||||
|
time_t start = time(NULL);
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
mtx_lock(&context->mutex_progress);
|
||||||
|
bool done = context->sender_done;
|
||||||
|
unsigned long long total = context->progress_bytes;
|
||||||
|
mtx_unlock(&context->mutex_progress);
|
||||||
|
|
||||||
|
if (done) {
|
||||||
|
time_t now = time(NULL);
|
||||||
|
double elapsed = difftime(now, start);
|
||||||
|
double rate = elapsed > 0.0 ? total / (1048576.0 * elapsed) : 0.0;
|
||||||
|
fprintf(stderr, "\rSent %.1f MB (%.1f MB/s) Done.\n", total / 1048576.0, rate);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
time_t now = time(NULL);
|
||||||
|
if (now - last_progress >= 1) {
|
||||||
|
last_progress = now;
|
||||||
|
double elapsed = difftime(now, start);
|
||||||
|
double rate = elapsed > 0.0 ? total / (1048576.0 * elapsed) : 0.0;
|
||||||
|
fprintf(stderr, "\rSent %.1f MB (%.1f MB/s) ", total / 1048576.0, rate);
|
||||||
|
fflush(stderr);
|
||||||
|
}
|
||||||
|
|
||||||
|
struct timespec ts = {0, 100 * 1000000L}; /* 100 ms */
|
||||||
|
thrd_sleep(&ts, NULL);
|
||||||
|
}
|
||||||
|
return thrd_success;
|
||||||
|
}
|
||||||
|
|
||||||
int send_files(Config* config) {
|
int send_files(Config* config) {
|
||||||
if (config->dry_run)
|
if (config->dry_run)
|
||||||
@@ -416,16 +513,20 @@ int send_files(Config* config) {
|
|||||||
client = client_create();
|
client = client_create();
|
||||||
if (!client || !client_connect_tls(client, config->server_host, config->server_port,
|
if (!client || !client_connect_tls(client, config->server_host, config->server_port,
|
||||||
config->tls_cert, config->tls_key, config->tls_ca)) {
|
config->tls_cert, config->tls_key, config->tls_ca)) {
|
||||||
if (client)
|
if (client) {
|
||||||
|
client_disconnect(client);
|
||||||
client_delete(client);
|
client_delete(client);
|
||||||
|
}
|
||||||
fprintf(stderr, "Error: could not connect to server via TLS\n");
|
fprintf(stderr, "Error: could not connect to server via TLS\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
client = client_create();
|
client = client_create();
|
||||||
if (!client || !client_connect(client, config->server_host, config->server_port)) {
|
if (!client || !client_connect(client, config->server_host, config->server_port)) {
|
||||||
if (client)
|
if (client) {
|
||||||
|
client_disconnect(client);
|
||||||
client_delete(client);
|
client_delete(client);
|
||||||
|
}
|
||||||
fprintf(stderr, "Error: could not connect to server\n");
|
fprintf(stderr, "Error: could not connect to server\n");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
@@ -439,9 +540,10 @@ int send_files(Config* config) {
|
|||||||
config->send_directory, config->use_metadata, config->chunk_size, config->exclude_patterns,
|
config->send_directory, config->use_metadata, config->chunk_size, config->exclude_patterns,
|
||||||
config->exclude_count, config->include_patterns, config->include_count, config->max_size,
|
config->exclude_count, config->include_patterns, config->include_count, config->max_size,
|
||||||
config->min_size, config->max_depth, config->follow_symlinks, config->copy_links,
|
config->min_size, config->max_depth, config->follow_symlinks, config->copy_links,
|
||||||
config->safe_links, config->copy_unsafe_links);
|
config->safe_links, config->copy_unsafe_links, config->checksum);
|
||||||
Chunk* current_chunk;
|
Chunk* current_chunk;
|
||||||
unsigned long long total_bytes = 0;
|
unsigned long long total_bytes = 0;
|
||||||
|
int total_files = 0;
|
||||||
time_t last_progress = 0;
|
time_t last_progress = 0;
|
||||||
time_t start = time(NULL);
|
time_t start = time(NULL);
|
||||||
ArrayList* manifest = config->use_delete ? array_list_create(free) : NULL;
|
ArrayList* manifest = config->use_delete ? array_list_create(free) : NULL;
|
||||||
@@ -449,11 +551,22 @@ int send_files(Config* config) {
|
|||||||
unsigned long long chunk_bytes = 0;
|
unsigned long long chunk_bytes = 0;
|
||||||
for (int i = 0; i < current_chunk->element_count; i++) {
|
for (int i = 0; i < current_chunk->element_count; i++) {
|
||||||
chunk_bytes += current_chunk->items[i]->data->size;
|
chunk_bytes += current_chunk->items[i]->data->size;
|
||||||
|
total_files++;
|
||||||
if (manifest) {
|
if (manifest) {
|
||||||
const char* p = current_chunk->items[i]->path;
|
const char* p = current_chunk->items[i]->path;
|
||||||
if (*p == '/')
|
if (*p == '/')
|
||||||
p++;
|
p++;
|
||||||
array_list_add(manifest, str_dup(p));
|
char* manifest_entry = str_dup(p);
|
||||||
|
if (!manifest_entry) {
|
||||||
|
log_message(LOG_LEVEL_ERROR, "Failed to allocate manifest entry");
|
||||||
|
chunk_destroy(current_chunk);
|
||||||
|
array_list_delete(manifest);
|
||||||
|
directory_scanner_destroy(scanner);
|
||||||
|
client_disconnect(client);
|
||||||
|
client_delete(client);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
array_list_add(manifest, manifest_entry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!config->use_sendfile) {
|
if (!config->use_sendfile) {
|
||||||
@@ -496,11 +609,16 @@ int send_files(Config* config) {
|
|||||||
goto send_fail;
|
goto send_fail;
|
||||||
Status s;
|
Status s;
|
||||||
int ok = receive_status(client->file_descriptor, &s) && s == STATUS_OK;
|
int ok = receive_status(client->file_descriptor, &s) && s == STATUS_OK;
|
||||||
|
double elapsed_total = difftime(time(NULL), start);
|
||||||
if (config->show_progress) {
|
if (config->show_progress) {
|
||||||
double elapsed = difftime(time(NULL), start);
|
double rate = elapsed_total > 0 ? total_bytes / (1048576.0 * elapsed_total) : 0;
|
||||||
double rate = elapsed > 0 ? total_bytes / (1048576.0 * elapsed) : 0;
|
|
||||||
fprintf(stderr, "\rSent %.1f MB (%.1f MB/s) Done.\n", total_bytes / 1048576.0, rate);
|
fprintf(stderr, "\rSent %.1f MB (%.1f MB/s) Done.\n", total_bytes / 1048576.0, rate);
|
||||||
}
|
}
|
||||||
|
if (config->stats) {
|
||||||
|
double rate = elapsed_total > 0 ? total_bytes / (1048576.0 * elapsed_total) : 0;
|
||||||
|
fprintf(stderr, "Stats: %d files, %.1f MB, %.1f MB/s\n", total_files, total_bytes / 1048576.0,
|
||||||
|
rate);
|
||||||
|
}
|
||||||
directory_scanner_destroy(scanner);
|
directory_scanner_destroy(scanner);
|
||||||
client_disconnect(client);
|
client_disconnect(client);
|
||||||
client_delete(client);
|
client_delete(client);
|
||||||
@@ -548,19 +666,59 @@ int send_files_multithreaded(Config* config) {
|
|||||||
context->manifest = array_list_create(free);
|
context->manifest = array_list_create(free);
|
||||||
|
|
||||||
thrd_t scanner, loader, sender;
|
thrd_t scanner, loader, sender;
|
||||||
if (thrd_create(&scanner, scan_directory_multithreaded, context) != thrd_success ||
|
bool scanner_created = false;
|
||||||
thrd_create(&loader, load_files_multithreaded, context) != thrd_success ||
|
bool loader_created = false;
|
||||||
thrd_create(&sender, send_chunks_multithreaded, context) != thrd_success) {
|
bool sender_created = false;
|
||||||
|
|
||||||
|
scanner_created = (thrd_create(&scanner, scan_directory_multithreaded, context) == thrd_success);
|
||||||
|
if (scanner_created)
|
||||||
|
loader_created = (thrd_create(&loader, load_files_multithreaded, context) == thrd_success);
|
||||||
|
if (scanner_created && loader_created)
|
||||||
|
sender_created = (thrd_create(&sender, send_chunks_multithreaded, context) == thrd_success);
|
||||||
|
|
||||||
|
if (!scanner_created || !loader_created || !sender_created) {
|
||||||
perror("Error creating threads.\n");
|
perror("Error creating threads.\n");
|
||||||
|
context->cancelled = true;
|
||||||
|
context->scanner_done = true;
|
||||||
|
context->loader_done = true;
|
||||||
|
context->sender_done = true;
|
||||||
|
cnd_broadcast(&context->condition_not_full_scanner);
|
||||||
|
cnd_broadcast(&context->condition_not_empty_scanner);
|
||||||
|
cnd_broadcast(&context->condition_not_full_loader);
|
||||||
|
cnd_broadcast(&context->condition_not_empty_loader);
|
||||||
|
if (sender_created)
|
||||||
|
thrd_join(sender, NULL);
|
||||||
|
if (loader_created)
|
||||||
|
thrd_join(loader, NULL);
|
||||||
|
if (scanner_created)
|
||||||
|
thrd_join(scanner, NULL);
|
||||||
pipeline_context_sender_destroy(context);
|
pipeline_context_sender_destroy(context);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
thrd_t progress;
|
||||||
|
bool progress_created = false;
|
||||||
|
if (config->show_progress) {
|
||||||
|
progress_created = (thrd_create(&progress, progress_thread_fn, context) == thrd_success);
|
||||||
|
if (!progress_created) {
|
||||||
|
perror("Error creating progress thread.\n");
|
||||||
|
/* Non-fatal; continue without progress reporting */
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
int sender_result;
|
int sender_result;
|
||||||
thrd_join(scanner, NULL);
|
thrd_join(scanner, NULL);
|
||||||
thrd_join(loader, NULL);
|
thrd_join(loader, NULL);
|
||||||
thrd_join(sender, &sender_result);
|
thrd_join(sender, &sender_result);
|
||||||
|
|
||||||
|
if (progress_created) {
|
||||||
|
/* Signal progress thread to exit if it hasn't already */
|
||||||
|
mtx_lock(&context->mutex_progress);
|
||||||
|
context->sender_done = true;
|
||||||
|
mtx_unlock(&context->mutex_progress);
|
||||||
|
thrd_join(progress, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
pipeline_context_sender_destroy(context);
|
pipeline_context_sender_destroy(context);
|
||||||
return sender_result == thrd_success ? 0 : 1;
|
return sender_result == thrd_success ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|||||||
+50
-13
@@ -27,10 +27,14 @@ static void dir_entry_destroy(void* item) {
|
|||||||
|
|
||||||
static DirEntry* dir_entry_create(const char* path, int depth) {
|
static DirEntry* dir_entry_create(const char* path, int depth) {
|
||||||
DirEntry* de = malloc(sizeof(DirEntry));
|
DirEntry* de = malloc(sizeof(DirEntry));
|
||||||
if (de) {
|
if (!de)
|
||||||
|
return NULL;
|
||||||
de->path = str_dup(path);
|
de->path = str_dup(path);
|
||||||
de->depth = depth;
|
if (!de->path) {
|
||||||
|
free(de);
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
de->depth = depth;
|
||||||
return de;
|
return de;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,7 +44,7 @@ DirectoryScanner* directory_scanner_create(const char* root_directory, bool use_
|
|||||||
int include_count, unsigned long long max_size,
|
int include_count, unsigned long long max_size,
|
||||||
unsigned long long min_size, int max_depth,
|
unsigned long long min_size, int max_depth,
|
||||||
bool follow_symlinks, bool copy_links, bool safe_links,
|
bool follow_symlinks, bool copy_links, bool safe_links,
|
||||||
bool copy_unsafe_links) {
|
bool copy_unsafe_links, bool checksum) {
|
||||||
DirectoryScanner* scanner = malloc(sizeof(DirectoryScanner));
|
DirectoryScanner* scanner = malloc(sizeof(DirectoryScanner));
|
||||||
if (scanner == NULL)
|
if (scanner == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -61,7 +65,19 @@ DirectoryScanner* directory_scanner_create(const char* root_directory, bool use_
|
|||||||
scanner->copy_links = copy_links;
|
scanner->copy_links = copy_links;
|
||||||
scanner->safe_links = safe_links;
|
scanner->safe_links = safe_links;
|
||||||
scanner->copy_unsafe_links = copy_unsafe_links;
|
scanner->copy_unsafe_links = copy_unsafe_links;
|
||||||
queue_enqueue(scanner->directories, dir_entry_create(root_directory, 0));
|
scanner->checksum = checksum;
|
||||||
|
DirEntry* root = dir_entry_create(root_directory, 0);
|
||||||
|
if (!root) {
|
||||||
|
queue_destroy(scanner->directories);
|
||||||
|
free(scanner);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (!queue_enqueue(scanner->directories, root)) {
|
||||||
|
dir_entry_destroy(root);
|
||||||
|
queue_destroy(scanner->directories);
|
||||||
|
free(scanner);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
return scanner;
|
return scanner;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,6 +292,7 @@ typedef struct {
|
|||||||
bool copy_links;
|
bool copy_links;
|
||||||
bool safe_links;
|
bool safe_links;
|
||||||
bool copy_unsafe_links;
|
bool copy_unsafe_links;
|
||||||
|
bool checksum;
|
||||||
} ParallelWorkerArg;
|
} ParallelWorkerArg;
|
||||||
|
|
||||||
static int parallel_worker_thread(void* arg) {
|
static int parallel_worker_thread(void* arg) {
|
||||||
@@ -284,7 +301,7 @@ static int parallel_worker_thread(void* arg) {
|
|||||||
DirectoryScanner* ds = directory_scanner_create(
|
DirectoryScanner* ds = directory_scanner_create(
|
||||||
wa->dirs[i], wa->use_metadata, wa->chunk_size, wa->exclude_patterns, wa->exclude_count,
|
wa->dirs[i], wa->use_metadata, wa->chunk_size, wa->exclude_patterns, wa->exclude_count,
|
||||||
wa->include_patterns, wa->include_count, wa->max_size, wa->min_size, wa->max_depth,
|
wa->include_patterns, wa->include_count, wa->max_size, wa->min_size, wa->max_depth,
|
||||||
wa->follow_symlinks, wa->copy_links, wa->safe_links, wa->copy_unsafe_links);
|
wa->follow_symlinks, wa->copy_links, wa->safe_links, wa->copy_unsafe_links, wa->checksum);
|
||||||
Chunk* chunk;
|
Chunk* chunk;
|
||||||
while ((chunk = directory_scanner_next(ds)) != NULL) {
|
while ((chunk = directory_scanner_next(ds)) != NULL) {
|
||||||
queue_enqueue_multithreaded(wa->ps->result_queue, chunk, &wa->ps->result_mutex,
|
queue_enqueue_multithreaded(wa->ps->result_queue, chunk, &wa->ps->result_mutex,
|
||||||
@@ -312,7 +329,7 @@ ParallelScanner* parallel_scanner_create(char* root_directory, bool use_metadata
|
|||||||
int include_count, unsigned long long max_size,
|
int include_count, unsigned long long max_size,
|
||||||
unsigned long long min_size, int max_depth,
|
unsigned long long min_size, int max_depth,
|
||||||
int num_threads, bool follow_symlinks, bool copy_links,
|
int num_threads, bool follow_symlinks, bool copy_links,
|
||||||
bool safe_links, bool copy_unsafe_links) {
|
bool safe_links, bool copy_unsafe_links, bool checksum) {
|
||||||
ParallelScanner* ps = calloc(1, sizeof(ParallelScanner));
|
ParallelScanner* ps = calloc(1, sizeof(ParallelScanner));
|
||||||
if (!ps)
|
if (!ps)
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -321,9 +338,28 @@ ParallelScanner* parallel_scanner_create(char* root_directory, bool use_metadata
|
|||||||
free(ps);
|
free(ps);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (mtx_init(&ps->result_mutex, mtx_plain) != thrd_success ||
|
int init = 0;
|
||||||
cnd_init(&ps->result_not_empty) != thrd_success ||
|
bool ok = true;
|
||||||
cnd_init(&ps->result_not_full) != thrd_success) {
|
if (mtx_init(&ps->result_mutex, mtx_plain) != thrd_success)
|
||||||
|
ok = false;
|
||||||
|
if (ok) {
|
||||||
|
init++;
|
||||||
|
if (cnd_init(&ps->result_not_empty) != thrd_success)
|
||||||
|
ok = false;
|
||||||
|
}
|
||||||
|
if (ok) {
|
||||||
|
// cppcheck-suppress unreadVariable
|
||||||
|
init++;
|
||||||
|
if (cnd_init(&ps->result_not_full) != thrd_success)
|
||||||
|
ok = false;
|
||||||
|
}
|
||||||
|
if (!ok) {
|
||||||
|
if (init >= 3)
|
||||||
|
cnd_destroy(&ps->result_not_full);
|
||||||
|
if (init >= 2)
|
||||||
|
cnd_destroy(&ps->result_not_empty);
|
||||||
|
if (init >= 1)
|
||||||
|
mtx_destroy(&ps->result_mutex);
|
||||||
queue_destroy(ps->result_queue);
|
queue_destroy(ps->result_queue);
|
||||||
free(ps);
|
free(ps);
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -353,8 +389,7 @@ ParallelScanner* parallel_scanner_create(char* root_directory, bool use_metadata
|
|||||||
bool is_symlink = S_ISLNK(lstats.st_mode);
|
bool is_symlink = S_ISLNK(lstats.st_mode);
|
||||||
|
|
||||||
// Skip symlinks unless the user explicitly enabled following/copying them.
|
// Skip symlinks unless the user explicitly enabled following/copying them.
|
||||||
if (is_symlink && !follow_symlinks && !copy_links && !safe_links &&
|
if (is_symlink && !follow_symlinks && !copy_links && !safe_links && !copy_unsafe_links) {
|
||||||
!copy_unsafe_links) {
|
|
||||||
free(cur_path);
|
free(cur_path);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -367,7 +402,7 @@ ParallelScanner* parallel_scanner_create(char* root_directory, bool use_metadata
|
|||||||
free(cur_path);
|
free(cur_path);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
link_target[len] = ' | |||||||