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: self
|
||||||
.torrents
|
.torrents
|
||||||
.iter()
|
.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,
|
*id,
|
||||||
SerializedTorrent {
|
SerializedTorrent {
|
||||||
trackers: torrent
|
trackers: torrent
|
||||||
|
|
@ -111,9 +114,9 @@ impl SessionDatabase {
|
||||||
only_files: torrent.only_files().clone(),
|
only_files: torrent.only_files().clone(),
|
||||||
is_paused: torrent
|
is_paused: torrent
|
||||||
.with_state(|s| matches!(s, ManagedTorrentState::Paused(_))),
|
.with_state(|s| matches!(s, ManagedTorrentState::Paused(_))),
|
||||||
output_folder: torrent.info().out_dir.clone(),
|
output_folder: output_folder.to_owned(),
|
||||||
},
|
},
|
||||||
)
|
))
|
||||||
})
|
})
|
||||||
.collect(),
|
.collect(),
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,10 @@ use crate::{opened_file::OpenedFile, torrent_state::ManagedTorrentInfo, type_ali
|
||||||
|
|
||||||
pub trait StorageFactory: Send + Sync {
|
pub trait StorageFactory: Send + Sync {
|
||||||
fn init_storage(&self, info: &ManagedTorrentInfo) -> anyhow::Result<Box<dyn TorrentStorage>>;
|
fn init_storage(&self, info: &ManagedTorrentInfo) -> anyhow::Result<Box<dyn TorrentStorage>>;
|
||||||
|
|
||||||
|
fn output_folder(&self) -> Option<&Path> {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub trait TorrentStorage: Send + Sync {
|
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 ensure_file_length(&self, file_id: usize, length: u64) -> anyhow::Result<()>;
|
||||||
|
|
||||||
fn take(&self) -> anyhow::Result<Box<dyn TorrentStorage>>;
|
fn take(&self) -> anyhow::Result<Box<dyn TorrentStorage>>;
|
||||||
|
|
||||||
|
fn output_folder(&self) -> Option<&Path> {
|
||||||
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct FilesystemStorageFactory {
|
pub struct FilesystemStorageFactory {
|
||||||
|
|
@ -68,6 +76,10 @@ impl StorageFactory for FilesystemStorageFactory {
|
||||||
opened_files: files,
|
opened_files: files,
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn output_folder(&self) -> Option<&Path> {
|
||||||
|
Some(&self.output_folder)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct FilesystemStorage {
|
pub struct FilesystemStorage {
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ pub struct ManagedTorrentInfo {
|
||||||
|
|
||||||
pub struct ManagedTorrent {
|
pub struct ManagedTorrent {
|
||||||
pub info: Arc<ManagedTorrentInfo>,
|
pub info: Arc<ManagedTorrentInfo>,
|
||||||
storage_factory: Box<dyn StorageFactory>,
|
pub(crate) storage_factory: Box<dyn StorageFactory>,
|
||||||
locked: RwLock<ManagedTorrentLocked>,
|
locked: RwLock<ManagedTorrentLocked>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -268,7 +268,7 @@ impl ManagedTorrent {
|
||||||
error_span!(parent: span.clone(), "initialize_and_start"),
|
error_span!(parent: span.clone(), "initialize_and_start"),
|
||||||
token.clone(),
|
token.clone(),
|
||||||
async move {
|
async move {
|
||||||
match init.check(&*self.storage_factory).await {
|
match init.check(&*t.storage_factory).await {
|
||||||
Ok(paused) => {
|
Ok(paused) => {
|
||||||
let mut g = t.locked.write();
|
let mut g = t.locked.write();
|
||||||
if let ManagedTorrentState::Initializing(_) = &g.state {
|
if let ManagedTorrentState::Initializing(_) = &g.state {
|
||||||
|
|
|
||||||
|
|
@ -461,10 +461,9 @@ async fn async_main(opts: Opts) -> anyhow::Result<()> {
|
||||||
Ok(v) => match v {
|
Ok(v) => match v {
|
||||||
AddTorrentResponse::AlreadyManaged(id, handle) => {
|
AddTorrentResponse::AlreadyManaged(id, handle) => {
|
||||||
info!(
|
info!(
|
||||||
"torrent {:?} is already managed, id={}, downloaded to {:?}",
|
"torrent {:?} is already managed, id={}",
|
||||||
handle.info_hash(),
|
handle.info_hash(),
|
||||||
id,
|
id,
|
||||||
handle.info().out_dir
|
|
||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue