Skip to content

Commit 020086f

Browse files
Allow --output to be directory (#546)
1 parent 9dd090d commit 020086f

File tree

1 file changed

+28
-2
lines changed

1 file changed

+28
-2
lines changed

src/subcommand/torrent/create.rs

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ impl Create {
319319

320320
let content = CreateContent::from_create(&self, &input, env)?;
321321

322-
let output = content.output.resolve(env)?;
322+
let mut output = content.output.resolve(env)?;
323323

324324
if content.piece_length.count() == 0 {
325325
return Err(Error::PieceLengthZero);
@@ -336,7 +336,11 @@ impl Create {
336336
return Err(Error::PieceLengthSmall);
337337
}
338338

339-
if let OutputTarget::Path(path) = &output {
339+
if let OutputTarget::Path(path) = &mut output {
340+
if path.is_dir() {
341+
path.push(format!("{}.torrent", content.name));
342+
}
343+
340344
if !self.force && path.exists() {
341345
return Err(Error::OutputExists { path: path.clone() });
342346
}
@@ -1014,6 +1018,28 @@ mod tests {
10141018
env.load_metainfo("x.torrent");
10151019
}
10161020

1021+
#[test]
1022+
fn destination_dir() {
1023+
let mut env = test_env! {
1024+
args: [
1025+
"torrent",
1026+
"create",
1027+
"--input",
1028+
"foo",
1029+
"--output",
1030+
"bar",
1031+
"--announce",
1032+
"http://bar",
1033+
],
1034+
tree: {
1035+
foo: "",
1036+
bar: {},
1037+
},
1038+
};
1039+
env.assert_ok();
1040+
env.load_metainfo("bar/foo.torrent");
1041+
}
1042+
10171043
#[test]
10181044
fn created_by_default() {
10191045
let mut env = test_env! {

0 commit comments

Comments
 (0)