Skip to content

Commit cf47ca5

Browse files
committed
Fix missing case-insensitive support
1 parent 0889275 commit cf47ca5

File tree

2 files changed

+24
-18
lines changed

2 files changed

+24
-18
lines changed

bin/annotate

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,11 @@ try {
9797
exit(1);
9898
}
9999

100+
$fileMap = [];
100101
$fileList = [];
101102
if (is_file($inputDir) && (str_ends_with($inputDir, '.lua') || str_ends_with($inputDir, '.xml'))) {
102-
$fileList[$inputDir] = pathinfo($inputDir, PATHINFO_EXTENSION);
103+
$fileList[] = $inputDir;
104+
$fileMap[strtolower($inputDir)] = $inputDir;
103105
} elseif (is_dir($inputDir)) {
104106
$inputDir = rtrim($inputDir, '/');
105107
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($inputDir));
@@ -111,10 +113,12 @@ if (is_file($inputDir) && (str_ends_with($inputDir, '.lua') || str_ends_with($in
111113
if ('toc' === $iterator->getExtension()) {
112114
$dirsWithToc[$iterator->getPath()] = true;
113115
}
116+
$filePath = $iterator->getPath() . '/' . $iterator->getFilename();
117+
$fileMap[strtolower($filePath)] = $filePath;
114118
$iterator->next();
115119
}
116120

117-
$tocParser = new TocFileParser($flavor);
121+
$tocParser = new TocFileParser($flavor, $fileMap);
118122
foreach (array_keys($dirsWithToc) as $dirWithToc) {
119123
$tocFile = $tocParser->findTocFile($dirWithToc);
120124
if ($tocFile) {

src/TocFileParser.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,20 @@ class TocFileParser
1111
{
1212
public function __construct(
1313
private readonly FlavorEnum $flavor,
14+
/**
15+
* @var array<string, string> [lowercase path => real path]
16+
*/
17+
private readonly array $normalizedPathsMap,
1418
) {
1519
}
1620

1721
public function findTocFile(string $dirWithToc): ?string
1822
{
19-
$dir = new DirectoryIterator($dirWithToc);
20-
$tocFiles = [];
21-
foreach ($dir as $fileInfo) {
22-
if ($fileInfo->isFile() && $fileInfo->getExtension() === 'toc') {
23-
$tocFiles[strtolower($fileInfo->getFilename())] = $fileInfo->getFilename();
24-
}
25-
}
2623
$dirName = basename($dirWithToc);
2724
foreach ($this->getSuffixesForFlavor($this->flavor) as $suffix) {
28-
$tocFileName = strtolower($dirName . $suffix . '.toc');
29-
if (isset($tocFiles[$tocFileName])) {
30-
return $dirWithToc . '/' . $tocFiles[$tocFileName];
25+
$tocFileName = strtolower($dirWithToc . '/' . $dirName . $suffix . '.toc');
26+
if (isset($this->normalizedPathsMap[$tocFileName])) {
27+
return $this->normalizedPathsMap[$tocFileName];
3128
}
3229
}
3330

@@ -117,10 +114,14 @@ public function listFiles(string $tocFilePath): array
117114

118115
$line = trim($line);
119116
$filePath = $dir . '/' . ltrim($line, '/');
120-
$files[] = $filePath;
117+
$realPath = $this->normalizedPathsMap[strtolower($filePath)] ?? null;
118+
if (!$realPath) {
119+
continue;
120+
}
121+
$files[] = $realPath;
121122

122123
if (str_ends_with($line, '.xml')) {
123-
$files = array_merge($files, $this->parseXmlIncludes($filePath));
124+
$files = array_merge($files, $this->parseXmlIncludes($realPath));
124125
}
125126
}
126127

@@ -195,10 +196,11 @@ private function parseXmlIncludes(string $filePath, ?array &$tree = null): array
195196
if ($file) {
196197
$file = (string) $file;
197198
$filePath = dirname($filePath) . '/' . ltrim($file, '/');
198-
if (is_file($filePath)) {
199-
$files[] = $filePath;
200-
if (str_ends_with($filePath, '.xml')) {
201-
$files = array_merge($files, $this->parseXmlIncludes($filePath, $tree));
199+
$realPath = $this->normalizedPathsMap[strtolower($filePath)] ?? null;
200+
if ($realPath) {
201+
$files[] = $realPath;
202+
if (str_ends_with($realPath, '.xml')) {
203+
$files = array_merge($files, $this->parseXmlIncludes($realPath, $tree));
202204
}
203205
}
204206
}

0 commit comments

Comments
 (0)