Skip to content

support seeding completed read-only files - #489

Draft
milahu wants to merge 2 commits into
ikatson:mainfrom
milahu:seed-read-only-2
Draft

support seeding completed read-only files#489
milahu wants to merge 2 commits into
ikatson:mainfrom
milahu:seed-read-only-2

Conversation

@milahu

@milahu milahu commented Sep 28, 2025

Copy link
Copy Markdown

fix #136

based on d980e29

alternative to #373

packaged in nur.repos.milahu.rqbit

building rqbit with rust 1.87 fails with

error[E0658]: `let` expressions in this position are unstable
  --> crates/librqbit_core/src/magnet.rs:41:16
   |
41 |             && let Ok(id20) = Id20::from_str(url)
   |                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   |
   = note: see issue #53667 <https://github.com/rust-lang/rust/issues/53667> for more information

this seems to work, but im getting these warnings

WARN librqbit::torrent_state::initializing: Error setting length for file "somefile.txt" to 12345: Os {
    code: 22,
    kind: InvalidInput,
    message: "Invalid argument",
} id=0 info_hash=xxxxxxxxx

@milahu

milahu commented Oct 6, 2025

Copy link
Copy Markdown
Author

this seems to work, but im getting these warnings

for some torrents, i also get these errors

error writing to file 0 (""some-file.txt"")

Caused by:
    0: error calling pwritev
    1: EBADF: Bad file number

Stack backtrace:
   0: <E as anyhow::context::ext::StdError>::ext_context
   1: <librqbit::storage::filesystem::fs::FilesystemStorage as librqbit::storage::TorrentStorage>::pwrite_all_vectored
   2: librqbit::torrent_state::live::PeerHandler::on_received_piece::write_to_disk
   3: tokio::runtime::scheduler::multi_thread::worker::block_in_place
   4: <librqbit::torrent_state::live::PeerHandler as librqbit::peer_connection::PeerConnectionHandler>::on_received_message
...

iPLAYCAFE-dev pushed a commit to iPLAYCAFE/rqbit that referenced this pull request Aug 25, 2026
When init() fails to open a file in read/write mode due to PermissionDenied
(common with antivirus, game launchers, backup tools), fall back to opening
in read-only mode. This is sufficient for seeding completed files.

Only applies to the allow_overwrite path where the file already exists.
The create_new path (first download) still fails on permission errors, as
write access is required.

Addresses: ikatson#136, ikatson#509
Related community PRs: ikatson#489, ikatson#373
iPLAYCAFE-dev pushed a commit to iPLAYCAFE/rqbit that referenced this pull request Aug 25, 2026
When opening a file in read/write mode fails with PermissionDenied or
Windows ERROR_SHARING_VIOLATION (code 32), retry in read-only mode.

This allows seeding of completed files that have been set to read-only
by the user or are locked by another process (antivirus, backup tools).
Completed files only need read access for seeding  if writing is
actually needed later, the write will fail gracefully at the OS level.

The fallback only applies in allow_overwrite mode (existing files).

Includes unit tests for:
- Normal read/write open path
- Read-only fallback behavior (unix)
- pread_exact after read-only fallback (unix)
- pwrite fails gracefully on read-only file (cross-platform)

Related: ikatson#136, ikatson#509
See also: ikatson#489, ikatson#373 (alternative approaches)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

support read-only downloaded files

1 participant