fix: only write IP cache after API call

previously, when the API call would fail (for whatever reason),
the cached IP had already been written, so following executions
wouldn't attempt to update the IP, even though the previous
attempt had failed.
This commit is contained in:
Jan Christian Grünhage 2020-04-20 23:13:42 +02:00
parent ec8b893f6a
commit 37bd9b1f24

View file

@ -62,15 +62,6 @@ fn main() -> Result<()> {
return Ok(());
}
if should_use_cache {
println!(
"Saving current IP {} to cache file {:?}...",
&current_ip,
&args.cache.clone().unwrap()
);
write_file(&args.cache.unwrap(), &current_ip)?;
}
let (api_token, zone, domain) = match args.config {
Some(c) => {
let config_str = read_file(&c)?;
@ -91,6 +82,15 @@ fn main() -> Result<()> {
&domain, &current_ip
);
if should_use_cache {
println!(
"Saving current IP {} to cache file {:?}...",
&current_ip,
&args.cache.clone().unwrap()
);
write_file(&args.cache.unwrap(), &current_ip)?;
}
Ok(())
}