History

Remove old extension dir when upgrading (#9800)

Fixes #9799 Release Notes: - Fixed a bug where upgrading an extension did not work correctly if the extension had switched from using an old extension schema with `extension.json` to the new schema with `extension.toml`.

Max Brunsfeld committed 2 years ago

Commit 5e7fcc01 parent 5adc51f1 file · +15 −6Browse files

Unified · Split

crates/extension/src/extension_store.rs+15−6
@@ -437,8 +437,9 @@ impl ExtensionStore { · 436 unmodified lines
437437 operation: ExtensionOperation,
438438 cx: &mut ModelContext<Self>,
439439 ) {
440− let extensions_dir = self.extensions_dir();
440+ let extension_dir = self.installed_dir.join(extension_id.as_ref());
441441 let http_client = self.http_client.clone();
442+ let fs = self.fs.clone();
442443
443444 match self.outstanding_operations.entry(extension_id.clone()) {
444445 hash_map::Entry::Occupied(_) => return,
@@ -463,11 +464,19 @@ impl ExtensionStore { · 18 unmodified lines
463464 .get(&url.as_ref(), Default::default(), true)
464465 .await
465466 .map_err(|err| anyhow!("error downloading extension: {}", err))?;
467+
468+ fs.remove_dir(
469+ &extension_dir,
470+ RemoveOptions {
471+ recursive: true,
472+ ignore_if_not_exists: true,
473+ },
474+ )
475+ .await?;
476+
466477 let decompressed_bytes = GzipDecoder::new(BufReader::new(response.body_mut()));
467478 let archive = Archive::new(decompressed_bytes);
468− archive
469− .unpack(extensions_dir.join(extension_id.as_ref()))
470− .await?;
479+ archive.unpack(extension_dir).await?;
471480 this.update(&mut cx, |this, cx| {
472481 this.reload(Some(extension_id.clone()), cx)
473482 })?
@@ -543,7 +552,7 @@ impl ExtensionStore { · 69 unmodified lines
543552 }
544553
545554 pub fn uninstall_extension(&mut self, extension_id: Arc<str>, cx: &mut ModelContext<Self>) {
546− let extensions_dir = self.extensions_dir();
555+ let extension_dir = self.installed_dir.join(extension_id.as_ref());
547556 let fs = self.fs.clone();
548557
549558 match self.outstanding_operations.entry(extension_id.clone()) {
@@ -566,7 +575,7 @@ impl ExtensionStore { · 16 unmodified lines
566575 });
567576
568577 fs.remove_dir(
569− &extensions_dir.join(extension_id.as_ref()),
578+ &extension_dir,
570579 RemoveOptions {
571580 recursive: true,
572581 ignore_if_not_exists: true,