diff --git a/modules/core/app-updater/index.ts b/modules/core/app-updater/index.ts index 5bc0e77..15b7d66 100644 --- a/modules/core/app-updater/index.ts +++ b/modules/core/app-updater/index.ts @@ -285,33 +285,33 @@ export async function ensureTargetFilesAreWriteable(updateFile: string) : Promis const errors: string[] = []; const tester = async (header: Headers) => { - const entry_path = path.normalize(path.join(parentPath, header.name)); + const entryPath = path.normalize(path.join(parentPath, header.name)); if(header.type == "file") { - if(originalFs.existsSync(entry_path)) { - code = await testAccess(entry_path, originalFs.constants.W_OK); + if(originalFs.existsSync(entryPath)) { + code = await testAccess(entryPath, originalFs.constants.W_OK); if(code) { - errors.push("Failed to acquire write permissions for file " + entry_path + " (Code " + code.code + ")"); + errors.push("Failed to acquire write permissions for file " + entryPath + " (Code " + code.code + ")"); } } else { - let directory = path.dirname(entry_path); + let directory = path.dirname(entryPath); while(directory.length != 0 && !originalFs.existsSync(directory)) { directory = path.normalize(path.join(directory, "..")); } code = await testAccess(directory, originalFs.constants.W_OK); if(code) { - errors.push("Failed to acquire write permissions for directory " + entry_path + " (Code " + code.code + ". Target directory " + directory + ")"); + errors.push("Failed to acquire write permissions for directory " + entryPath + " (Code " + code.code + ". Target directory " + directory + ")"); } } } else if(header.type == "directory") { - let directory = path.dirname(entry_path); + let directory = path.dirname(entryPath); while(directory.length != 0 && !originalFs.existsSync(directory)) { directory = path.normalize(path.join(directory, "..")); } code = await testAccess(directory, originalFs.constants.W_OK); if(code) { - errors.push("Failed to acquire write permissions for directory " + entry_path + " (Code " + code.code + ". Target directory " + directory + ")"); + errors.push("Failed to acquire write permissions for directory " + entryPath + " (Code " + code.code + ". Target directory " + directory + ")"); } } }; @@ -667,31 +667,10 @@ export async function prepareUpdateExecute(targetVersion: UpdateVersion, callbac } callbackStats("Downloading update", 0); - const updateFilePath = await downloadClientVersion(targetVersion.channel, targetVersion.version, status => { callbackStats("Downloading update", status.percent); }, callbackLog); - /* TODO: Remove this step and let the actual updater so this. If this fails we'll already receiving appropriate error messages. */ - if(os.platform() !== "win32") { - callbackLog("info", "Checking file permissions"); - callbackStats("Checking file permissions", .25); - - /* We must be on a unix based system */ - const inaccessiblePaths = await ensureTargetFilesAreWriteable(updateFilePath); - if(inaccessiblePaths.length > 0) { - console.log("Failed to access the following files:"); - for(const fail of inaccessiblePaths) { - console.log(" - " + fail); - } - - const executeCommand = "sudo " + path.normalize(app.getPath("exe")) + " --no-sandbox --update-execute"; - throw "Failed to access target files.\nPlease execute this app with administrator (sudo) privileges.\nUse the following command:\n" + executeCommand; - } - } else { - /* the windows update already requests admin privileges */ - } - callbackStats("Extracting update", .5); const { updateSourceDirectory, updateInstallerExecutable } = await extractUpdateFile(updateFilePath, callbackLog); @@ -722,8 +701,31 @@ export async function prepareUpdateExecute(targetVersion: UpdateVersion, callbac if(os.platform() == "linux") { console.log("Executing update install on linux"); + /* We must be on a unix based system */ + callbackLog("info", "Checking file permissions"); + const inaccessiblePaths = await ensureTargetFilesAreWriteable(updateFilePath); + if(inaccessiblePaths.length > 0) { + console.log("Failed to access the following files:"); + for(const fail of inaccessiblePaths) { + console.log(" - " + fail); + } + console.log("Will prompt the user to execute a command"); + } + //We have to unpack it later executeCallback = () => { + if(inaccessiblePaths.length > 0) { + dialog.showMessageBoxSync({ + buttons: [ "Ok" ], + title: "Update available", + message: + "We don't have permissions to write to all files.\n" + + "Please execute the following command to execute the update:\n" + + `sudo "${updateInstallerExecutable}" "${installLogFile}" "${installConfigFile}"` + }); + return; + } + console.log("Executing command %s with args %o", updateInstallerExecutable, [installLogFile, installConfigFile]); try { let result = child_process.spawnSync(updateInstallerExecutable, [installLogFile, installConfigFile]); @@ -736,6 +738,7 @@ export async function prepareUpdateExecute(targetVersion: UpdateVersion, callbac "Failed to execute update installer\n" + "Installer exited with code " + result.status } as MessageBoxOptions); + return; } } catch(error) { console.error("Failed to execute update installer (%o)", error); diff --git a/modules/core/main.ts b/modules/core/main.ts index c60cb70..f450383 100644 --- a/modules/core/main.ts +++ b/modules/core/main.ts @@ -1,6 +1,6 @@ import * as electron from "electron"; -import {app, Menu, protocol} from "electron"; +import {app, Menu} from "electron"; import MessageBoxOptions = electron.MessageBoxOptions; import {processArguments, parseProcessArguments, Arguments} from "../shared/process-arguments";