Skip to content

Commit

Permalink
Allow --output to be directory (#546)
Browse files Browse the repository at this point in the history
  • Loading branch information
shreyasminocha authored Jan 22, 2025
1 parent 9dd090d commit 020086f
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/subcommand/torrent/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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() });
}
Expand Down Expand Up @@ -1014,6 +1018,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! {
Expand Down

0 comments on commit 020086f

Please sign in to comment.