Skip to content

Commit 2aefb25

Browse files
authored
Check and remove execute permission from the config file on Unix platforms (#317)
1 parent 943b701 commit 2aefb25

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

shell/AIShell.Kernel/Command/AgentCommand.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,26 @@ private void ConfigAgentAction(string name, string editor)
166166
else
167167
{
168168
// On macOS and Linux, we just depend on the default editor.
169+
FileInfo fileInfo = new(settingFile);
170+
if (fileInfo.Exists)
171+
{
172+
UnixFileMode curMode = fileInfo.UnixFileMode;
173+
UnixFileMode newMode = curMode & ~(UnixFileMode.UserExecute | UnixFileMode.GroupExecute | UnixFileMode.OtherExecute);
174+
175+
if (newMode != curMode)
176+
{
177+
try
178+
{
179+
File.SetUnixFileMode(settingFile, newMode);
180+
}
181+
catch (UnauthorizedAccessException)
182+
{
183+
host.WriteErrorLine($"The setting file '{settingFile}' is incorrectly configured with the 'execute' permission. Please remove the 'execute' permission and try again.");
184+
return;
185+
}
186+
}
187+
}
188+
169189
info = new(settingFile) { UseShellExecute = true };
170190
Process.Start(info);
171191
}

0 commit comments

Comments
 (0)