Skip to content

Commit 3d7200b

Browse files
committed
move target logic
1 parent c13e583 commit 3d7200b

File tree

1 file changed

+17
-30
lines changed

1 file changed

+17
-30
lines changed

plugins/updater/src/updater.rs

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -297,13 +297,6 @@ impl UpdaterBuilder {
297297
};
298298

299299
let arch = get_updater_arch().ok_or(Error::UnsupportedArch)?;
300-
let (target, json_target) = if let Some(target) = self.target {
301-
(target.clone(), target)
302-
} else {
303-
let target = get_updater_target().ok_or(Error::UnsupportedOs)?;
304-
let json_target = format!("{target}-{arch}");
305-
(target.to_owned(), json_target)
306-
};
307300

308301
let executable_path = self.executable_path.clone().unwrap_or(current_exe()?);
309302

@@ -326,8 +319,7 @@ impl UpdaterBuilder {
326319
installer_args: self.installer_args,
327320
current_exe_args: self.current_exe_args,
328321
arch,
329-
target,
330-
json_target,
322+
target: self.target,
331323
headers: self.headers,
332324
extract_path,
333325
on_before_exit: self.on_before_exit,
@@ -359,10 +351,7 @@ pub struct Updater {
359351
proxy: Option<Url>,
360352
endpoints: Vec<Url>,
361353
arch: &'static str,
362-
// The `{{target}}` variable we replace in the endpoint and serach for in the JSON
363-
target: String,
364-
// The value we search if the updater server returns a JSON with the `platforms` object
365-
json_target: String,
354+
target: Option<String>,
366355
headers: HeaderMap,
367356
extract_path: PathBuf,
368357
on_before_exit: Option<OnBeforeExit>,
@@ -403,6 +392,13 @@ impl Updater {
403392
std::env::set_var("SSL_CERT_DIR", "/etc/ssl/certs");
404393
}
405394
}
395+
let (target, json_target) = if let Some(target) = &self.target {
396+
(target.clone(), target.clone())
397+
} else {
398+
let target = get_updater_target().ok_or(Error::UnsupportedOs)?;
399+
let json_target = format!("{target}-{}", self.arch);
400+
(target.to_owned(), json_target)
401+
};
406402

407403
let mut remote_release: Option<RemoteRelease> = None;
408404
let mut raw_json: Option<serde_json::Value> = None;
@@ -425,11 +421,11 @@ impl Updater {
425421
.to_string()
426422
// url::Url automatically url-encodes the path components
427423
.replace("%7B%7Bcurrent_version%7D%7D", &encoded_version)
428-
.replace("%7B%7Btarget%7D%7D", &self.target)
424+
.replace("%7B%7Btarget%7D%7D", &target)
429425
.replace("%7B%7Barch%7D%7D", self.arch)
430426
// but not query parameters
431427
.replace("{{current_version}}", &encoded_version)
432-
.replace("{{target}}", &self.target)
428+
.replace("{{target}}", &target)
433429
.replace("{{arch}}", self.arch)
434430
.parse()?;
435431

@@ -510,13 +506,13 @@ impl Updater {
510506
None => release.version > self.current_version,
511507
};
512508

513-
let mut download_url = release.download_url(&self.json_target);
514-
let mut signature = release.signature(&self.json_target);
509+
let mut download_url = release.download_url(&json_target);
510+
let mut signature = release.signature(&json_target);
515511

516512
let installer = self.get_updater_installer();
517513

518514
if let Some(installer) = installer {
519-
let target = &format!("{}-{}", &self.json_target, installer.suffix());
515+
let target = &format!("{}-{}", &json_target, installer.suffix());
520516
log::debug!(
521517
"Bundle type is {}. Checking for plattform {target} in response",
522518
installer.suffix()
@@ -525,10 +521,7 @@ impl Updater {
525521
let bundle_signature = release.signature(target);
526522
if bundle_url.is_err() || bundle_signature.is_err() {
527523
if download_url.is_err() || signature.is_err() {
528-
return Err(Error::TargetsNotFound(
529-
self.json_target.clone(),
530-
target.clone(),
531-
));
524+
return Err(Error::TargetsNotFound(json_target.clone(), target.clone()));
532525
}
533526
log::debug!("Plattform {target} not found in response. Using fallback URL");
534527
} else {
@@ -537,11 +530,8 @@ impl Updater {
537530
signature = bundle_signature;
538531
}
539532
} else if download_url.is_err() || signature.is_err() {
540-
log::debug!(
541-
"Bundle type is not known and fallback platform {} was not found in response",
542-
self.json_target
543-
);
544-
return Err(Error::TargetNotFound(self.json_target.clone()));
533+
log::debug!("Bundle type is not known and fallback platform {json_target} was not found in response");
534+
return Err(Error::TargetNotFound(json_target.clone()));
545535
}
546536

547537
let update = if should_update {
@@ -551,7 +541,6 @@ impl Updater {
551541
on_before_exit: self.on_before_exit.clone(),
552542
app_name: self.app_name.clone(),
553543
current_version: self.current_version.to_string(),
554-
target: self.target.clone(),
555544
extract_path: self.extract_path.clone(),
556545
version: release.version.to_string(),
557546
date: release.pub_date,
@@ -590,8 +579,6 @@ pub struct Update {
590579
pub version: String,
591580
/// Update publish date
592581
pub date: Option<OffsetDateTime>,
593-
/// Target
594-
pub target: String,
595582
/// Current installer
596583
pub installer: Option<Installer>,
597584
/// Download URL announced

0 commit comments

Comments
 (0)