This commit is contained in:
Igor Katson 2024-08-21 16:12:20 +01:00
parent b4512e4809
commit 451debedbb
No known key found for this signature in database
GPG key ID: B4EC22B66D61A3F5
19 changed files with 127 additions and 114 deletions

View file

@ -128,7 +128,7 @@ impl JsonSessionPersistenceStore {
write_torrent_file: bool,
) -> anyhow::Result<()> {
if !torrent
.info
.shared
.storage_factory
.is_type_id(TypeId::of::<FilesystemStorageFactory>())
{
@ -137,7 +137,7 @@ impl JsonSessionPersistenceStore {
let st = SerializedTorrent {
trackers: torrent
.info()
.shared()
.trackers
.iter()
.map(|u| u.to_string())
@ -147,10 +147,10 @@ impl JsonSessionPersistenceStore {
torrent_bytes: Default::default(),
only_files: torrent.only_files().clone(),
is_paused: torrent.with_state(|s| matches!(s, ManagedTorrentState::Paused(_))),
output_folder: torrent.info().options.output_folder.clone(),
output_folder: torrent.shared().options.output_folder.clone(),
};
if write_torrent_file && !torrent.info().torrent_bytes.is_empty() {
if write_torrent_file && !torrent.shared().torrent_bytes.is_empty() {
let torrent_bytes_file = self.torrent_bytes_filename(&torrent.info_hash());
match tokio::fs::OpenOptions::new()
.create(true)
@ -160,7 +160,7 @@ impl JsonSessionPersistenceStore {
.await
{
Ok(mut f) => {
if let Err(e) = f.write_all(&torrent.info().torrent_bytes).await {
if let Err(e) = f.write_all(&torrent.shared().torrent_bytes).await {
warn!(error=?e, file=?torrent_bytes_file, "error writing torrent bytes")
}
}

View file

@ -96,7 +96,7 @@ impl SessionPersistenceStore for PostgresSessionStorage {
}
async fn store(&self, id: TorrentId, torrent: &ManagedTorrentHandle) -> anyhow::Result<()> {
let torrent_bytes: &[u8] = &torrent.info().torrent_bytes;
let torrent_bytes: &[u8] = &torrent.shared().torrent_bytes;
let q = "INSERT INTO torrents (id, info_hash, torrent_bytes, trackers, output_folder, only_files, is_paused)
VALUES($1, $2, $3, $4, $5, $6, $7)
ON CONFLICT(id) DO NOTHING";
@ -104,10 +104,17 @@ impl SessionPersistenceStore for PostgresSessionStorage {
.bind::<i32>(id.try_into()?)
.bind(&torrent.info_hash().0[..])
.bind(torrent_bytes)
.bind(torrent.info().trackers.iter().cloned().collect::<Vec<_>>())
.bind(
torrent
.info()
.shared()
.trackers
.iter()
.cloned()
.collect::<Vec<_>>(),
)
.bind(
torrent
.shared()
.options
.output_folder
.to_str()