Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Allow --output to be a directory #546

Merged
merged 5 commits into from
Jan 22, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading