Skip to content

Commit

Permalink
fix: take torrent private flag from torrent file
Browse files Browse the repository at this point in the history
We were assuming "private" to be always true and we have to use the
value inside the torrent file.
  • Loading branch information
josecelano committed Nov 30, 2022
1 parent 72dc139 commit 309e141
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 9 deletions.
7 changes: 3 additions & 4 deletions src/upgrades/from_v1_0_0_to_v2_0_0/databases/sqlite_v2_0_0.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ pub struct TorrentRecordV2 {
pub name: String,
pub pieces: String,
pub piece_length: i64,
pub private: bool,
pub private: Option<u8>,
pub root_hash: i64,
pub date_uploaded: String,
}
Expand All @@ -33,7 +33,6 @@ impl TorrentRecordV2 {
torrent: &TorrentRecordV1,
torrent_info: &TorrentInfo,
uploader: &UserRecordV1,
private: bool,
) -> Self {
Self {
torrent_id: torrent.torrent_id,
Expand All @@ -44,7 +43,7 @@ impl TorrentRecordV2 {
name: torrent_info.name.clone(),
pieces: torrent_info.get_pieces_as_string(),
piece_length: torrent_info.piece_length,
private,
private: torrent_info.private,
root_hash: torrent_info.get_root_hash_as_i64(),
date_uploaded: convert_timestamp_to_datetime(torrent.upload_date),
}
Expand Down Expand Up @@ -208,7 +207,7 @@ impl SqliteDatabaseV2_0_0 {
.bind(torrent.name.clone())
.bind(torrent.pieces.clone())
.bind(torrent.piece_length)
.bind(torrent.private)
.bind(torrent.private.unwrap_or(0))
.bind(torrent.root_hash)
.bind(torrent.date_uploaded.clone())
.execute(&self.pool)
Expand Down
6 changes: 1 addition & 5 deletions src/upgrades/from_v1_0_0_to_v2_0_0/upgrader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,6 @@ async fn transfer_torrents(
&torrent.torrent_id
);

// All torrents were public in version v1.0.0
let private = false;

let uploader = source_database
.get_user_by_username(&torrent.uploader)
.await
Expand All @@ -292,8 +289,7 @@ async fn transfer_torrents(
.insert_torrent(&TorrentRecordV2::from_v1_data(
torrent,
&torrent_from_file.info,
&uploader,
private,
&uploader
))
.await
.unwrap();
Expand Down

0 comments on commit 309e141

Please sign in to comment.