fix: remove dead HasPrefix branch in config dir pattern matching

The strings.HasPrefix(lowerRelativePath, pattern+sep) check was dead code
because relativePath always starts with a path separator after TrimPrefix
from a filepath.Clean'd configRoot. Since pattern values like 'sites-available'
don't start with '/', HasPrefix with 'pattern+sep' (e.g., 'sites-available/')
could never match a path starting with '/sites-available/'.

The Contains(lowerRelativePath, sep+pattern+sep) check already correctly
handles this case since it looks for '/pattern/' anywhere in the path.
This commit is contained in:
Cursor Agent
2026-02-07 12:32:50 +00:00
parent e1c6fcea4d
commit deb0ad7590
+3 -7
View File
@@ -368,16 +368,12 @@ func isConfigFilePath(filePath string) bool {
// are typically config files. Use separator-bounded matching to avoid false positives
// like "myconf.db" matching "conf.d" across the name/extension boundary
for _, pattern := range configDirPatterns {
// Check if pattern appears in the middle of path (with slashes on both sides)
// Check if pattern appears in the path (with slashes on both sides)
// This covers both middle-of-path and start-of-path cases since relativePath
// always starts with a separator after TrimPrefix from a Clean'd configRoot
if strings.Contains(lowerRelativePath, sep+pattern+sep) {
return true
}
// Check if path starts with this directory name (after config root)
// Note: We only check pattern+sep here because sep+pattern+sep is already covered
// by the Contains check above (if a string starts with X, it contains X)
if strings.HasPrefix(lowerRelativePath, pattern+sep) {
return true
}
}
// Files with .conf extension are config files