Fail early if destination .torrent file exists
Check if torrent file to create exists and fail early. type: changed
This commit is contained in:
parent
4371bb1402
commit
2cfdad2597
|
@ -50,6 +50,8 @@ pub(crate) enum Error {
|
||||||
NodeParsePort { text: String, source: ParseIntError },
|
NodeParsePort { text: String, source: ParseIntError },
|
||||||
#[snafu(display("Failed to find opener utility, please install one of {}", tried.join(",")))]
|
#[snafu(display("Failed to find opener utility, please install one of {}", tried.join(",")))]
|
||||||
OpenerMissing { tried: &'static [&'static str] },
|
OpenerMissing { tried: &'static [&'static str] },
|
||||||
|
#[snafu(display("Output path already exists: `{}`", path.display()))]
|
||||||
|
OutputExists { path: PathBuf },
|
||||||
#[snafu(display(
|
#[snafu(display(
|
||||||
"Interal error, this may indicate a bug in intermodal: {}\n\
|
"Interal error, this may indicate a bug in intermodal: {}\n\
|
||||||
Consider filing an issue: https://github.com/casey/imdl/issues/new",
|
Consider filing an issue: https://github.com/casey/imdl/issues/new",
|
||||||
|
|
|
@ -265,6 +265,14 @@ impl Create {
|
||||||
OutputTarget::File(input.parent().unwrap().join(torrent_name))
|
OutputTarget::File(input.parent().unwrap().join(torrent_name))
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if let OutputTarget::File(path) = &output {
|
||||||
|
if !self.force && path.exists() {
|
||||||
|
return Err(Error::OutputExists {
|
||||||
|
path: path.to_owned(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let private = if self.private { Some(true) } else { None };
|
let private = if self.private { Some(true) } else { None };
|
||||||
|
|
||||||
let creation_date = if self.no_creation_date {
|
let creation_date = if self.no_creation_date {
|
||||||
|
@ -1586,8 +1594,8 @@ Content Size 9 bytes
|
||||||
};
|
};
|
||||||
assert_matches!(
|
assert_matches!(
|
||||||
env.run().unwrap_err(),
|
env.run().unwrap_err(),
|
||||||
Error::Filesystem {source, path}
|
Error::OutputExists {path}
|
||||||
if path == env.resolve("foo.torrent") && source.kind() == io::ErrorKind::AlreadyExists
|
if path == env.resolve("foo.torrent")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user