From b7831efd4ef09d0d004a0dbb8c688776ea5b5e03 Mon Sep 17 00:00:00 2001 From: Dongbo Wang Date: Thu, 5 Dec 2024 16:31:06 -0800 Subject: [PATCH] Check and remove execute permission from the config file --- shell/AIShell.Kernel/Command/AgentCommand.cs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/shell/AIShell.Kernel/Command/AgentCommand.cs b/shell/AIShell.Kernel/Command/AgentCommand.cs index 63522feb..7d993fd5 100644 --- a/shell/AIShell.Kernel/Command/AgentCommand.cs +++ b/shell/AIShell.Kernel/Command/AgentCommand.cs @@ -166,6 +166,26 @@ private void ConfigAgentAction(string name, string editor) else { // On macOS and Linux, we just depend on the default editor. + FileInfo fileInfo = new(settingFile); + if (fileInfo.Exists) + { + UnixFileMode curMode = fileInfo.UnixFileMode; + UnixFileMode newMode = curMode & ~(UnixFileMode.UserExecute | UnixFileMode.GroupExecute | UnixFileMode.OtherExecute); + + if (newMode != curMode) + { + try + { + File.SetUnixFileMode(settingFile, newMode); + } + catch (UnauthorizedAccessException) + { + host.WriteErrorLine($"The setting file '{settingFile}' is incorrectly configured with the 'execute' permission. Please remove the 'execute' permission and try again."); + return; + } + } + } + info = new(settingFile) { UseShellExecute = true }; Process.Start(info); }