Skip to content

Commit

Permalink
Check and remove execute permission from the config file
Browse files Browse the repository at this point in the history
  • Loading branch information
daxian-dbw committed Dec 6, 2024
1 parent 943b701 commit b7831ef
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions shell/AIShell.Kernel/Command/AgentCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down

0 comments on commit b7831ef

Please sign in to comment.