Skip to content

Commit 815ccab

Browse files
committed
Move macOS app rename migration to updater startup
Signed-off-by: Yujong Lee <yujonglee.dev@gmail.com>
1 parent e10a8cf commit 815ccab

File tree

8 files changed

+231
-700
lines changed

8 files changed

+231
-700
lines changed

Cargo.lock

Lines changed: 0 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

plugins/updater2/Cargo.toml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,8 @@ tokio = { workspace = true, features = ["macros", "time"] }
2222
tauri = { workspace = true, features = ["test"] }
2323
tauri-specta = { workspace = true, features = ["derive", "typescript"] }
2424

25-
flate2 = "1"
2625
serde = { workspace = true }
2726
specta = { workspace = true }
2827
strum = { workspace = true, features = ["derive"] }
29-
tar = "0.4"
30-
tempfile = { workspace = true }
31-
3228
thiserror = { workspace = true }
3329
tracing = { workspace = true }

plugins/updater2/js/bindings.gen.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ updatedEvent: "plugin:updater2:updated-event"
6464

6565
/** user-defined types **/
6666

67-
export type InstallResult = { kind: "relaunch_current" } | { kind: "macos_bundle_update"; current_path: string; staged_path: string; target_path: string; backup_path: string; stage_dir: string }
67+
export type InstallResult = { kind: "relaunch_current" }
6868
export type UpdateDownloadFailedEvent = { version: string }
6969
export type UpdateDownloadingEvent = { version: string }
7070
export type UpdateReadyEvent = { version: string }

plugins/updater2/src/error.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,8 @@ pub enum Error {
2020
VersionMismatch { expected: String, actual: String },
2121
#[error("failed to determine current app path")]
2222
FailedToDetermineCurrentAppPath,
23-
#[error("failed to determine target app path")]
24-
FailedToDetermineTargetAppPath,
25-
#[error("invalid update archive: {0}")]
26-
InvalidUpdateArchive(String),
2723
#[error("failed to schedule installed app launch at {path}: {details}")]
2824
FailedToScheduleInstalledAppLaunch { path: String, details: String },
29-
#[error("macOS authorization step failed: {details}")]
30-
MacosAuthorizationFailed { details: String },
31-
#[error("macOS target bundle already exists at {path}")]
32-
MacosTargetBundleConflict { path: String },
33-
#[error("invalid postinstall state: {0}")]
34-
InvalidPostinstallState(String),
3525
}
3626

3727
impl Serialize for Error {

plugins/updater2/src/ext.rs

Lines changed: 2 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,6 @@ use crate::events::{
1313
#[serde(tag = "kind", rename_all = "snake_case")]
1414
pub enum InstallResult {
1515
RelaunchCurrent,
16-
MacosBundleUpdate {
17-
current_path: String,
18-
staged_path: String,
19-
target_path: String,
20-
backup_path: String,
21-
stage_dir: String,
22-
},
2316
}
2417

2518
pub struct Updater2<'a, R: tauri::Runtime, M: tauri::Manager<R>> {
@@ -189,79 +182,16 @@ impl<'a, R: tauri::Runtime, M: tauri::Manager<R>> Updater2<'a, R, M> {
189182
let _ = store.save();
190183
}
191184

192-
#[cfg(target_os = "macos")]
193-
{
194-
let stage_dir = self.create_macos_update_stage_dir(version)?;
195-
let staged_update = match crate::migration::stage_macos_update(&bytes, &stage_dir) {
196-
Ok(staged_update) => staged_update,
197-
Err(err) => {
198-
let _ = std::fs::remove_dir_all(&stage_dir);
199-
return Err(err);
200-
}
201-
};
202-
203-
Ok(InstallResult::MacosBundleUpdate {
204-
current_path: staged_update.current_app_path.display().to_string(),
205-
staged_path: staged_update.staged_app_path.display().to_string(),
206-
target_path: staged_update.target_app_path.display().to_string(),
207-
backup_path: staged_update.current_backup_path.display().to_string(),
208-
stage_dir: staged_update.stage_dir.display().to_string(),
209-
})
210-
}
211-
212-
#[cfg(not(target_os = "macos"))]
213-
{
214-
update.install(&bytes)?;
215-
Ok(InstallResult::RelaunchCurrent)
216-
}
185+
update.install(&bytes)?;
186+
Ok(InstallResult::RelaunchCurrent)
217187
}
218188

219189
pub async fn postinstall(&self, result: InstallResult) -> Result<(), crate::Error> {
220190
match result {
221191
InstallResult::RelaunchCurrent => {
222192
self.manager.app_handle().restart();
223193
}
224-
InstallResult::MacosBundleUpdate {
225-
current_path,
226-
staged_path,
227-
target_path,
228-
backup_path,
229-
stage_dir,
230-
} => {
231-
#[cfg(target_os = "macos")]
232-
{
233-
let handle = self.manager.app_handle().clone();
234-
let current_pid = std::process::id();
235-
236-
crate::migration::schedule_macos_update_after_exit(
237-
current_pid,
238-
crate::migration::StagedMacosUpdate {
239-
current_app_path: PathBuf::from(current_path),
240-
staged_app_path: PathBuf::from(staged_path),
241-
target_app_path: PathBuf::from(target_path),
242-
current_backup_path: PathBuf::from(backup_path),
243-
stage_dir: PathBuf::from(stage_dir),
244-
},
245-
)?;
246-
247-
handle.exit(0);
248-
}
249-
#[cfg(not(target_os = "macos"))]
250-
{
251-
let _ = (
252-
current_path,
253-
staged_path,
254-
target_path,
255-
backup_path,
256-
stage_dir,
257-
);
258-
return Err(crate::Error::InvalidPostinstallState(
259-
"macos_bundle_update is only valid on macOS".into(),
260-
));
261-
}
262-
}
263194
}
264-
Ok(())
265195
}
266196
}
267197

@@ -295,48 +225,3 @@ fn get_cache_path<R: tauri::Runtime, M: tauri::Manager<R>>(
295225
.map(|p: PathBuf| p.join("updates"))?;
296226
Some(dir.join(format!("{}.bin", version)))
297227
}
298-
299-
#[cfg(target_os = "macos")]
300-
impl<'a, R: tauri::Runtime, M: tauri::Manager<R>> Updater2<'a, R, M> {
301-
fn create_macos_update_stage_dir(&self, version: &str) -> Result<PathBuf, crate::Error> {
302-
let base_dir = self
303-
.manager
304-
.app_handle()
305-
.path()
306-
.app_cache_dir()
307-
.map_err(|_| crate::Error::CachePathUnavailable)?
308-
.join("updates")
309-
.join("staged");
310-
std::fs::create_dir_all(&base_dir)?;
311-
312-
let version = sanitize_path_component(version);
313-
let current_pid = std::process::id();
314-
315-
for attempt in 0..100 {
316-
let nanos = std::time::SystemTime::now()
317-
.duration_since(std::time::UNIX_EPOCH)
318-
.unwrap_or_default()
319-
.as_nanos();
320-
let stage_dir = base_dir.join(format!("{version}-{current_pid}-{nanos}-{attempt}"));
321-
322-
match std::fs::create_dir(&stage_dir) {
323-
Ok(()) => return Ok(stage_dir),
324-
Err(err) if err.kind() == std::io::ErrorKind::AlreadyExists => continue,
325-
Err(err) => return Err(err.into()),
326-
}
327-
}
328-
329-
Err(crate::Error::CachePathUnavailable)
330-
}
331-
}
332-
333-
#[cfg(target_os = "macos")]
334-
fn sanitize_path_component(value: &str) -> String {
335-
value
336-
.chars()
337-
.map(|ch| match ch {
338-
'a'..='z' | 'A'..='Z' | '0'..='9' | '-' | '_' | '.' => ch,
339-
_ => '_',
340-
})
341-
.collect()
342-
}

plugins/updater2/src/lib.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ mod error;
33
mod events;
44
mod ext;
55
#[cfg(target_os = "macos")]
6-
mod migration;
6+
mod startup_migration;
77
mod store;
88

99
pub use error::{Error, Result};
@@ -40,6 +40,13 @@ pub fn init<R: tauri::Runtime>() -> tauri::plugin::TauriPlugin<R> {
4040
.setup(move |app, _api| {
4141
specta_builder.mount_events(app);
4242

43+
#[cfg(target_os = "macos")]
44+
match startup_migration::maybe_schedule_legacy_bundle_rename_on_launch(app) {
45+
Ok(true) => {}
46+
Ok(false) => {}
47+
Err(err) => tracing::error!("failed to schedule legacy bundle rename: {}", err),
48+
}
49+
4350
let handle = app.clone();
4451
tauri::async_runtime::spawn(async move {
4552
loop {

0 commit comments

Comments
 (0)