From 57119352f031c2a928f7556ba5956293c8f7da6c Mon Sep 17 00:00:00 2001 From: Shreyas Minocha Date: Sat, 28 Dec 2024 23:12:30 +0530 Subject: [PATCH 1/4] Allow `--output` to be a directory fixes: #525 --- src/subcommand/torrent/create/create_content.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/subcommand/torrent/create/create_content.rs b/src/subcommand/torrent/create/create_content.rs index d39e5a3..3dd60a6 100644 --- a/src/subcommand/torrent/create/create_content.rs +++ b/src/subcommand/torrent/create/create_content.rs @@ -61,11 +61,17 @@ impl CreateContent { .to_owned(), }; - let output = create + let mut output = create .output .clone() .unwrap_or_else(|| OutputTarget::Path(Self::torrent_path(path, &name))); + if let OutputTarget::Path(path) = &output { + if path.is_dir() { + output = OutputTarget::Path(path.join(format!("{name}.torrent"))); + } + } + Ok(Self { files: Some(files), piece_length, From 7812ad21a9090a0605ff96e2ab3f00e915bc47e2 Mon Sep 17 00:00:00 2001 From: Shreyas Minocha Date: Sun, 29 Dec 2024 00:56:03 +0530 Subject: [PATCH 2/4] Add output directory test --- src/subcommand/torrent/create.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/subcommand/torrent/create.rs b/src/subcommand/torrent/create.rs index a505af7..2b9b0ed 100644 --- a/src/subcommand/torrent/create.rs +++ b/src/subcommand/torrent/create.rs @@ -1014,6 +1014,28 @@ mod tests { env.load_metainfo("x.torrent"); } + #[test] + fn destination_dir() { + let mut env = test_env! { + args: [ + "torrent", + "create", + "--input", + "foo", + "--output", + "bar", + "--announce", + "http://bar", + ], + tree: { + foo: "", + bar: {}, + }, + }; + env.assert_ok(); + env.load_metainfo("bar/foo.torrent"); + } + #[test] fn created_by_default() { let mut env = test_env! { From dc6053b0782cc508ab9f434aa9e62f9d54b7e2d9 Mon Sep 17 00:00:00 2001 From: Shreyas Minocha Date: Tue, 7 Jan 2025 18:40:05 -0500 Subject: [PATCH 3/4] Fix failing output directory test --- src/subcommand/torrent/create/create_content.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/subcommand/torrent/create/create_content.rs b/src/subcommand/torrent/create/create_content.rs index 3dd60a6..08c4c89 100644 --- a/src/subcommand/torrent/create/create_content.rs +++ b/src/subcommand/torrent/create/create_content.rs @@ -66,7 +66,9 @@ impl CreateContent { .clone() .unwrap_or_else(|| OutputTarget::Path(Self::torrent_path(path, &name))); - if let OutputTarget::Path(path) = &output { + let resolved = output.resolve(env)?; + + if let OutputTarget::Path(path) = &resolved { if path.is_dir() { output = OutputTarget::Path(path.join(format!("{name}.torrent"))); } From 0117cc2ffd429e493c6d6c7234f722faee3c066d Mon Sep 17 00:00:00 2001 From: Casey Rodarmor Date: Tue, 21 Jan 2025 16:27:00 -0800 Subject: [PATCH 4/4] Tweak --- src/subcommand/torrent/create.rs | 8 ++++++-- src/subcommand/torrent/create/create_content.rs | 10 +--------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/subcommand/torrent/create.rs b/src/subcommand/torrent/create.rs index 49e9af7..fc4bd8f 100644 --- a/src/subcommand/torrent/create.rs +++ b/src/subcommand/torrent/create.rs @@ -319,7 +319,7 @@ impl Create { let content = CreateContent::from_create(&self, &input, env)?; - let output = content.output.resolve(env)?; + let mut output = content.output.resolve(env)?; if content.piece_length.count() == 0 { return Err(Error::PieceLengthZero); @@ -336,7 +336,11 @@ impl Create { return Err(Error::PieceLengthSmall); } - if let OutputTarget::Path(path) = &output { + if let OutputTarget::Path(path) = &mut output { + if path.is_dir() { + path.push(format!("{}.torrent", content.name)); + } + if !self.force && path.exists() { return Err(Error::OutputExists { path: path.clone() }); } diff --git a/src/subcommand/torrent/create/create_content.rs b/src/subcommand/torrent/create/create_content.rs index 08c4c89..d39e5a3 100644 --- a/src/subcommand/torrent/create/create_content.rs +++ b/src/subcommand/torrent/create/create_content.rs @@ -61,19 +61,11 @@ impl CreateContent { .to_owned(), }; - let mut output = create + let output = create .output .clone() .unwrap_or_else(|| OutputTarget::Path(Self::torrent_path(path, &name))); - let resolved = output.resolve(env)?; - - if let OutputTarget::Path(path) = &resolved { - if path.is_dir() { - output = OutputTarget::Path(path.join(format!("{name}.torrent"))); - } - } - Ok(Self { files: Some(files), piece_length,