Skip to content

Commit

Permalink
fix: [torrust#282] downloaded torrent info-hash matches uploaded one
Browse files Browse the repository at this point in the history
NOTICE: They only matche when the index doesn't change it becuase it
removs non-standard fields from the `info` key dictionary. They should
match if the uploaded torrent does not have any non-stanrdard field in
the `info` dictionary key.
  • Loading branch information
josecelano committed Sep 13, 2023
1 parent b34c7d8 commit 6ff3600
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 15 deletions.
4 changes: 1 addition & 3 deletions src/databases/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,8 +442,6 @@ impl Database for Mysql {
(root_hash.to_string(), true)
};

let private = torrent.info.private.unwrap_or(0);

// add torrent
let torrent_id = query("INSERT INTO torrust_torrents (uploader_id, category_id, info_hash, size, name, pieces, piece_length, private, root_hash, `source`, date_uploaded) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, UTC_TIMESTAMP())")
.bind(uploader_id)
Expand All @@ -453,7 +451,7 @@ impl Database for Mysql {
.bind(torrent.info.name.to_string())
.bind(pieces)
.bind(torrent.info.piece_length)
.bind(private)
.bind(torrent.info.private)
.bind(root_hash)
.bind(torrent.info.source.clone())
.execute(&mut tx)
Expand Down
4 changes: 1 addition & 3 deletions src/databases/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,8 +432,6 @@ impl Database for Sqlite {
(root_hash.to_string(), true)
};

let private = torrent.info.private.unwrap_or(0);

// add torrent
let torrent_id = query("INSERT INTO torrust_torrents (uploader_id, category_id, info_hash, size, name, pieces, piece_length, private, root_hash, `source`, date_uploaded) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, strftime('%Y-%m-%d %H:%M:%S',DATETIME('now', 'utc')))")
.bind(uploader_id)
Expand All @@ -443,7 +441,7 @@ impl Database for Sqlite {
.bind(torrent.info.name.to_string())
.bind(pieces)
.bind(torrent.info.piece_length)
.bind(private)
.bind(torrent.info.private)
.bind(root_hash)
.bind(torrent.info.source.clone())
.execute(&mut tx)
Expand Down
6 changes: 2 additions & 4 deletions src/models/torrent_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,6 @@ impl Torrent {
/// This function will panic if the `torrent_info.pieces` is not a valid hex string.
#[must_use]
pub fn from_new_torrent_info_request(torrent_info: NewTorrentInfoRequest) -> Self {
let private = u8::try_from(torrent_info.private.unwrap_or(0)).ok();

// the info part of the torrent file
let mut info = TorrentInfo {
name: torrent_info.name.to_string(),
Expand All @@ -123,7 +121,7 @@ impl Torrent {
md5sum: None,
length: None,
files: None,
private,
private: torrent_info.private,
path: None,
root_hash: None,
source: None,
Expand Down Expand Up @@ -296,7 +294,7 @@ pub struct DbTorrentInfo {
pub pieces: String,
pub piece_length: i64,
#[serde(default)]
pub private: Option<i64>,
pub private: Option<u8>,
pub root_hash: i64,
}

Expand Down
4 changes: 2 additions & 2 deletions src/services/torrent_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub struct NewTorrentInfoRequest {
pub name: String,
pub pieces: String,
pub piece_length: i64,
pub private: Option<i64>,
pub private: Option<u8>,
pub root_hash: i64,
pub files: Vec<TorrentFile>,
pub announce_urls: Vec<Vec<String>>,
Expand Down Expand Up @@ -77,7 +77,7 @@ mod tests {
md5sum: None,
length: Some(37),
files: None,
private: Some(0),
private: None,
path: None,
root_hash: None,
source: None,
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ pub const ENV_VAR_E2E_CONFIG_PATH: &str = "TORRUST_IDX_BACK_E2E_CONFIG_PATH";

// Default values

pub const ENV_VAR_E2E_DEFAULT_CONFIG_PATH: &str = "./config-idx-back.local.toml";
pub const ENV_VAR_E2E_DEFAULT_CONFIG_PATH: &str = "./config-idx-back.sqlite.local.toml";

/// Initialize configuration from file or env var.
///
Expand Down
6 changes: 4 additions & 2 deletions tests/e2e/web/api/v1/contexts/torrent/asserts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,12 @@ pub async fn expected_torrent(mut uploaded_torrent: Torrent, env: &TestEnv, down
None => None,
};

uploaded_torrent.info.private = Some(0);
uploaded_torrent.announce = Some(build_announce_url(&tracker_url, &tracker_key));
uploaded_torrent.encoding = None;
uploaded_torrent.announce_list = Some(build_announce_list(&tracker_url, &tracker_key));

// These fields are not persisted in the database yet.
// See https://github.com/torrust/torrust-index-backend/issues/284
uploaded_torrent.encoding = None;
uploaded_torrent.creation_date = None;
uploaded_torrent.created_by = None;

Expand Down

0 comments on commit 6ff3600

Please sign in to comment.