fix(llm_tools): fix permission checking to use relative path (#1473)
The has_permission_to_access function was incorrectly using absolute paths when checking against gitignore patterns. This could cause issues when the binary name matches the project root directory name, particularly in Go projects. Changes: - Extract relative path from absolute path by removing project root prefix - Use relative path for gitignore pattern matching - Add comments explaining the path handling logic Signed-off-by: Hanchin Hsieh <me@yuchanns.xyz>
This commit is contained in:
@@ -30,7 +30,12 @@ local function has_permission_to_access(abs_path)
|
||||
if abs_path:sub(1, #project_root) ~= project_root then return false end
|
||||
local gitignore_path = project_root .. "/.gitignore"
|
||||
local gitignore_patterns, gitignore_negate_patterns = Utils.parse_gitignore(gitignore_path)
|
||||
return not Utils.is_ignored(abs_path, gitignore_patterns, gitignore_negate_patterns)
|
||||
-- The checker should only take care of the path inside the project root
|
||||
-- Specifically, it should not check the project root itself
|
||||
-- Otherwise if the binary is named the same as the project root (such as Go binary), any paths
|
||||
-- insde the project root will be ignored
|
||||
local rel_path = Path:new(abs_path):make_relative(project_root)
|
||||
return not Utils.is_ignored(rel_path, gitignore_patterns, gitignore_negate_patterns)
|
||||
end
|
||||
|
||||
---@type AvanteLLMToolFunc<{ rel_path: string, max_depth?: integer }>
|
||||
|
||||
Reference in New Issue
Block a user