From 906f8a8d633182c8744215195ee78439f821729b Mon Sep 17 00:00:00 2001 From: Chris Morrell Date: Mon, 13 Nov 2023 23:04:57 -0500 Subject: [PATCH 1/4] WIP --- src/Support/ModuleRegistry.php | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/Support/ModuleRegistry.php b/src/Support/ModuleRegistry.php index 68828e9..b21cfd3 100644 --- a/src/Support/ModuleRegistry.php +++ b/src/Support/ModuleRegistry.php @@ -11,10 +11,13 @@ class ModuleRegistry { protected ?Collection $modules = null; + protected string $modules_real_path; + public function __construct( protected string $modules_path, protected string $cache_path ) { + $this->modules_real_path = realpath($this->modules_path); } public function getModulesPath(): string @@ -104,9 +107,25 @@ protected function extractModuleNameFromPath(string $path): string // Handle Windows-style paths $path = str_replace('\\', '/', $path); - $relative_path = trim(Str::after($path, $this->modules_path), '/'); + $modules_path = str_replace('\\', '/', $this->modules_path); + $modules_real_path = str_replace('\\', '/', $this->modules_real_path); + + $prefix = str_starts_with($path, $modules_real_path) + ? $modules_real_path + : $modules_path; + + $relative_path = trim(Str::after($path, $prefix), '/'); $segments = explode('/', $relative_path); + dump([ + sprintf('path = %s', $path), + sprintf('modules_path = %s', $modules_path), + sprintf('modules_real_path = %s', $modules_real_path), + sprintf('prefix = %s', $prefix), + sprintf('relative_path = %s', $relative_path), + sprintf('name = %s', $segments[0]), + ]); + return $segments[0]; } } From 78b8e6756d0ca7e4c36de1a9abf1babf1f6b57a6 Mon Sep 17 00:00:00 2001 From: Chris Morrell Date: Mon, 13 Nov 2023 23:12:12 -0500 Subject: [PATCH 2/4] WIPWIPWIP --- src/Support/ModuleRegistry.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Support/ModuleRegistry.php b/src/Support/ModuleRegistry.php index b21cfd3..bf35bbd 100644 --- a/src/Support/ModuleRegistry.php +++ b/src/Support/ModuleRegistry.php @@ -110,7 +110,7 @@ protected function extractModuleNameFromPath(string $path): string $modules_path = str_replace('\\', '/', $this->modules_path); $modules_real_path = str_replace('\\', '/', $this->modules_real_path); - $prefix = str_starts_with($path, $modules_real_path) + $prefix = '' !== $modules_real_path && str_starts_with($path, $modules_real_path) ? $modules_real_path : $modules_path; From ca2f1d88a44dbe31d88e0231822e197c27a0a041 Mon Sep 17 00:00:00 2001 From: Chris Morrell Date: Mon, 13 Nov 2023 23:17:15 -0500 Subject: [PATCH 3/4] WOMPWOMP --- src/Support/ModuleRegistry.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Support/ModuleRegistry.php b/src/Support/ModuleRegistry.php index bf35bbd..a8bb479 100644 --- a/src/Support/ModuleRegistry.php +++ b/src/Support/ModuleRegistry.php @@ -11,13 +11,10 @@ class ModuleRegistry { protected ?Collection $modules = null; - protected string $modules_real_path; - public function __construct( protected string $modules_path, protected string $cache_path ) { - $this->modules_real_path = realpath($this->modules_path); } public function getModulesPath(): string @@ -108,7 +105,7 @@ protected function extractModuleNameFromPath(string $path): string $path = str_replace('\\', '/', $path); $modules_path = str_replace('\\', '/', $this->modules_path); - $modules_real_path = str_replace('\\', '/', $this->modules_real_path); + $modules_real_path = str_replace('\\', '/', realpath($this->modules_path)); $prefix = '' !== $modules_real_path && str_starts_with($path, $modules_real_path) ? $modules_real_path From 2c03c81cb04b64c395a64a8c1c23adb19b2047f8 Mon Sep 17 00:00:00 2001 From: Chris Morrell Date: Mon, 13 Nov 2023 23:26:40 -0500 Subject: [PATCH 4/4] Clean up --- src/Support/ModuleRegistry.php | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/src/Support/ModuleRegistry.php b/src/Support/ModuleRegistry.php index a8bb479..c576b6d 100644 --- a/src/Support/ModuleRegistry.php +++ b/src/Support/ModuleRegistry.php @@ -104,25 +104,14 @@ protected function extractModuleNameFromPath(string $path): string // Handle Windows-style paths $path = str_replace('\\', '/', $path); - $modules_path = str_replace('\\', '/', $this->modules_path); - $modules_real_path = str_replace('\\', '/', realpath($this->modules_path)); - - $prefix = '' !== $modules_real_path && str_starts_with($path, $modules_real_path) - ? $modules_real_path - : $modules_path; - - $relative_path = trim(Str::after($path, $prefix), '/'); - $segments = explode('/', $relative_path); - - dump([ - sprintf('path = %s', $path), - sprintf('modules_path = %s', $modules_path), - sprintf('modules_real_path = %s', $modules_real_path), - sprintf('prefix = %s', $prefix), - sprintf('relative_path = %s', $relative_path), - sprintf('name = %s', $segments[0]), - ]); + // If the modules directory is symlinked, we may get two paths that are actually + // in the same directory, but have different prefixes. This helps resolve that. + if (Str::startsWith($path, $this->modules_path)) { + $path = trim(Str::after($path, $this->modules_path), '/'); + } elseif (Str::startsWith($path, $modules_real_path = str_replace('\\', '/', realpath($this->modules_path)))) { + $path = trim(Str::after($path, $modules_real_path), '/'); + } - return $segments[0]; + return explode('/', $path)[0]; } }