Fail early if destination .torrent file exists

Check if torrent file to create exists and fail early.

type: changed
This commit is contained in:
Casey Rodarmor 2020-03-12 01:01:26 -07:00
parent 4371bb1402
commit 2cfdad2597
No known key found for this signature in database
GPG Key ID: 556186B153EC6FE0
2 changed files with 12 additions and 2 deletions

View File

@ -50,6 +50,8 @@ pub(crate) enum Error {
NodeParsePort { text: String, source: ParseIntError },
#[snafu(display("Failed to find opener utility, please install one of {}", tried.join(",")))]
OpenerMissing { tried: &'static [&'static str] },
#[snafu(display("Output path already exists: `{}`", path.display()))]
OutputExists { path: PathBuf },
#[snafu(display(
"Interal error, this may indicate a bug in intermodal: {}\n\
Consider filing an issue: https://github.com/casey/imdl/issues/new",

View File

@ -265,6 +265,14 @@ impl Create {
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 creation_date = if self.no_creation_date {
@ -1586,8 +1594,8 @@ Content Size 9 bytes
};
assert_matches!(
env.run().unwrap_err(),
Error::Filesystem {source, path}
if path == env.resolve("foo.torrent") && source.kind() == io::ErrorKind::AlreadyExists
Error::OutputExists {path}
if path == env.resolve("foo.torrent")
)
}