It compiles now
This commit is contained in:
parent
42bbf84ea5
commit
67c22c9313
4 changed files with 22 additions and 8 deletions
|
|
@ -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(),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<Box<dyn TorrentStorage>>;
|
||||
|
||||
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<Box<dyn TorrentStorage>>;
|
||||
|
||||
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 {
|
||||
|
|
|
|||
|
|
@ -107,7 +107,7 @@ pub struct ManagedTorrentInfo {
|
|||
|
||||
pub struct ManagedTorrent {
|
||||
pub info: Arc<ManagedTorrentInfo>,
|
||||
storage_factory: Box<dyn StorageFactory>,
|
||||
pub(crate) storage_factory: Box<dyn StorageFactory>,
|
||||
locked: RwLock<ManagedTorrentLocked>,
|
||||
}
|
||||
|
||||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue