Clone storage factories...

This commit is contained in:
Igor Katson 2024-05-02 20:16:14 +01:00
parent 07a5b69a25
commit 427f490a61
10 changed files with 62 additions and 21 deletions

View file

@ -16,10 +16,7 @@ use crate::{
peer_connection::PeerConnectionOptions,
read_buf::ReadBuf,
spawn_utils::BlockingSpawner,
storage::{
filesystem::{FilesystemStorageFactory, MmapFilesystemStorageFactory},
BoxStorageFactory, StorageFactoryExt,
},
storage::{filesystem::FilesystemStorageFactory, BoxStorageFactory, StorageFactoryExt},
torrent_state::{
ManagedTorrentBuilder, ManagedTorrentHandle, ManagedTorrentState, TorrentStateLive,
},
@ -193,7 +190,7 @@ pub struct Session {
default_defer_writes: bool,
// default_storage_factory: Option<BoxStorageFactory>,
default_storage_factory: Option<BoxStorageFactory>,
// This is stored for all tasks to stop when session is dropped.
_cancellation_token_drop_guard: DropGuard,
@ -430,7 +427,8 @@ pub struct SessionOptions {
// If true, will write to disk in separate threads. The downside is additional allocations.
// May be useful if the disk is slow.
pub default_defer_writes: bool,
// pub default_storage_factory: Option<BoxStorageFactory>,
pub default_storage_factory: Option<BoxStorageFactory>,
}
async fn create_tcp_listener(
@ -530,6 +528,7 @@ impl Session {
cancellation_token: token,
tcp_listen_port,
default_defer_writes: opts.default_defer_writes,
default_storage_factory: opts.default_storage_factory,
});
if let Some(tcp_listener) = tcp_listener {
@ -1023,9 +1022,8 @@ impl Session {
let storage_factory = opts
.storage_factory
.take()
// .unwrap_or_else(|| self.default_storage_factory.clone())
// .unwrap_or_else(|| FilesystemStorageFactory::default().boxed());
.unwrap_or_else(|| MmapFilesystemStorageFactory::default().boxed());
.or_else(|| self.default_storage_factory.as_ref().map(|f| f.clone_box()))
.unwrap_or_else(|| FilesystemStorageFactory::default().boxed());
if opts.list_only {
return Ok(AddTorrentResponse::ListOnly(ListOnlyResponse {