diff --git a/crates/librqbit/src/session.rs b/crates/librqbit/src/session.rs index 25ffad8..a999b5a 100644 --- a/crates/librqbit/src/session.rs +++ b/crates/librqbit/src/session.rs @@ -96,8 +96,11 @@ impl SessionDatabase { torrents: self .torrents .iter() - .map(|(id, torrent)| { - ( + .filter_map(|(id, torrent)| { + // This will skip serializing torrents that don't have an output folder. + // This is for backwards compat not to change serialization format. + let output_folder = torrent.storage_factory.output_folder()?; + Some(( *id, SerializedTorrent { trackers: torrent @@ -111,9 +114,9 @@ impl SessionDatabase { only_files: torrent.only_files().clone(), is_paused: torrent .with_state(|s| matches!(s, ManagedTorrentState::Paused(_))), - output_folder: torrent.info().out_dir.clone(), + output_folder: output_folder.to_owned(), }, - ) + )) }) .collect(), } diff --git a/crates/librqbit/src/storage.rs b/crates/librqbit/src/storage.rs index 5c3c1de..f06dede 100644 --- a/crates/librqbit/src/storage.rs +++ b/crates/librqbit/src/storage.rs @@ -13,6 +13,10 @@ use crate::{opened_file::OpenedFile, torrent_state::ManagedTorrentInfo, type_ali pub trait StorageFactory: Send + Sync { fn init_storage(&self, info: &ManagedTorrentInfo) -> anyhow::Result>; + + fn output_folder(&self) -> Option<&Path> { + None + } } pub trait TorrentStorage: Send + Sync { @@ -25,6 +29,10 @@ pub trait TorrentStorage: Send + Sync { fn ensure_file_length(&self, file_id: usize, length: u64) -> anyhow::Result<()>; fn take(&self) -> anyhow::Result>; + + fn output_folder(&self) -> Option<&Path> { + None + } } pub struct FilesystemStorageFactory { @@ -68,6 +76,10 @@ impl StorageFactory for FilesystemStorageFactory { opened_files: files, })) } + + fn output_folder(&self) -> Option<&Path> { + Some(&self.output_folder) + } } pub struct FilesystemStorage { diff --git a/crates/librqbit/src/torrent_state/mod.rs b/crates/librqbit/src/torrent_state/mod.rs index 2990b73..6c71db6 100644 --- a/crates/librqbit/src/torrent_state/mod.rs +++ b/crates/librqbit/src/torrent_state/mod.rs @@ -107,7 +107,7 @@ pub struct ManagedTorrentInfo { pub struct ManagedTorrent { pub info: Arc, - storage_factory: Box, + pub(crate) storage_factory: Box, locked: RwLock, } @@ -268,7 +268,7 @@ impl ManagedTorrent { error_span!(parent: span.clone(), "initialize_and_start"), token.clone(), async move { - match init.check(&*self.storage_factory).await { + match init.check(&*t.storage_factory).await { Ok(paused) => { let mut g = t.locked.write(); if let ManagedTorrentState::Initializing(_) = &g.state { diff --git a/crates/rqbit/src/main.rs b/crates/rqbit/src/main.rs index e0a8bd2..e97114a 100644 --- a/crates/rqbit/src/main.rs +++ b/crates/rqbit/src/main.rs @@ -461,10 +461,9 @@ async fn async_main(opts: Opts) -> anyhow::Result<()> { Ok(v) => match v { AddTorrentResponse::AlreadyManaged(id, handle) => { info!( - "torrent {:?} is already managed, id={}, downloaded to {:?}", + "torrent {:?} is already managed, id={}", handle.info_hash(), id, - handle.info().out_dir ); continue; }