Skip to content

Commit

Permalink
fix: handle spaces in artifact name for all linux platforms instead o…
Browse files Browse the repository at this point in the history
…f only .deb (#8403)
  • Loading branch information
xyloflake committed Aug 10, 2024
1 parent f7daeb9 commit 1c14820
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/old-ducks-cry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"electron-updater": minor
---

Handle spaces for all linux package managers
15 changes: 14 additions & 1 deletion packages/electron-updater/src/BaseUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,20 @@ export abstract class BaseUpdater extends AppUpdater {
}

const downloadedUpdateHelper = this.downloadedUpdateHelper
const installerPath = downloadedUpdateHelper == null ? null : downloadedUpdateHelper.file

Check warning on line 51 in packages/electron-updater/src/BaseUpdater.ts

View workflow job for this annotation

GitHub Actions / test-linux (ArtifactPublisherTest,BuildTest,ExtraBuildTest,RepoSlugTest,binDownloadTest,configura...

Delete `····`

Check warning on line 51 in packages/electron-updater/src/BaseUpdater.ts

View workflow job for this annotation

GitHub Actions / test-linux (snapTest,debTest,fpmTest,protonTest)

Delete `····`
// Get the installer path, ensuring spaces are escaped on Linux
// 1. Check if downloadedUpdateHelper is not null
// 2. Check if downloadedUpdateHelper.file is not null
// 3. If both checks pass:
// a. If the platform is Linux, replace spaces with '\ ' for shell compatibility
// b. If the platform is not Linux, use the original path
// 4. If any check fails, set installerPath to null
const installerPath = downloadedUpdateHelper && downloadedUpdateHelper.file

Check warning on line 59 in packages/electron-updater/src/BaseUpdater.ts

View workflow job for this annotation

GitHub Actions / test-linux (ArtifactPublisherTest,BuildTest,ExtraBuildTest,RepoSlugTest,binDownloadTest,configura...

Replace `·downloadedUpdateHelper·&&·downloadedUpdateHelper.file·⏎······?·(process.platform·===·'linux'·⏎········?·downloadedUpdateHelper.file.replace(/·/g,·'\\·')·⏎········:·downloadedUpdateHelper.file)·⏎······:·null;` with `⏎······downloadedUpdateHelper·&&·downloadedUpdateHelper.file·?·(process.platform·===·"linux"·?·downloadedUpdateHelper.file.replace(/·/g,·"\\·")·:·downloadedUpdateHelper.file)·:·null`

Check warning on line 59 in packages/electron-updater/src/BaseUpdater.ts

View workflow job for this annotation

GitHub Actions / test-linux (snapTest,debTest,fpmTest,protonTest)

Replace `·downloadedUpdateHelper·&&·downloadedUpdateHelper.file·⏎······?·(process.platform·===·'linux'·⏎········?·downloadedUpdateHelper.file.replace(/·/g,·'\\·')·⏎········:·downloadedUpdateHelper.file)·⏎······:·null;` with `⏎······downloadedUpdateHelper·&&·downloadedUpdateHelper.file·?·(process.platform·===·"linux"·?·downloadedUpdateHelper.file.replace(/·/g,·"\\·")·:·downloadedUpdateHelper.file)·:·null`
? (process.platform === 'linux'
? downloadedUpdateHelper.file.replace(/ /g, '\\ ')
: downloadedUpdateHelper.file)
: null;

const downloadedFileInfo = downloadedUpdateHelper == null ? null : downloadedUpdateHelper.downloadedFileInfo
if (installerPath == null || downloadedFileInfo == null) {
this.dispatchError(new Error("No valid update available, can't quit and install"))
Expand Down
5 changes: 1 addition & 4 deletions packages/electron-updater/src/DebUpdater.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,7 @@ export class DebUpdater extends BaseUpdater {
const sudo = this.wrapSudo()
// pkexec doesn't want the command to be wrapped in " quotes
const wrapper = /pkexec/i.test(sudo) ? "" : `"`
// application artifact names may include spaces in their name which leads
// to an error when the install command is executed
const installerPath = options.installerPath.replace(/ /g, "\\ ")
const cmd = ["dpkg", "-i", installerPath, "||", "apt-get", "install", "-f", "-y"]
const cmd = ["dpkg", "-i", options.installerPath, "||", "apt-get", "install", "-f", "-y"]
this.spawnSyncLog(sudo, [`${wrapper}/bin/bash`, "-c", `'${cmd.join(" ")}'${wrapper}`])
if (options.isForceRunAfter) {
this.app.relaunch()
Expand Down

0 comments on commit 1c14820

Please sign in to comment.