diff --git a/CHANGELOG.md b/CHANGELOG.md index 89d6fcf..ef1e3b9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## [Unreleased] + +### Fixed + +- Taking over a socket address in a simulated environment (as it tried to delete a concrete file) + ## 4.0.0 - 2026-01-25 ### Added diff --git a/src/Internal/Capabilities.php b/src/Internal/Capabilities.php index 3a66a73..13f91c2 100644 --- a/src/Internal/Capabilities.php +++ b/src/Internal/Capabilities.php @@ -64,7 +64,7 @@ public function streams(): Capabilities\Streams public function sockets(): Capabilities\Sockets { - return $this->implementation->sockets(); + return $this->implementation->sockets($this->files()); } public function watch(): Watch diff --git a/src/Internal/Capabilities/AmbientAuthority.php b/src/Internal/Capabilities/AmbientAuthority.php index 3a3035a..abaf387 100644 --- a/src/Internal/Capabilities/AmbientAuthority.php +++ b/src/Internal/Capabilities/AmbientAuthority.php @@ -35,9 +35,9 @@ public function streams(): Streams } #[\Override] - public function sockets(): Sockets + public function sockets(Files $files): Sockets { - return Sockets::of(); + return Sockets::of($files); } #[\Override] diff --git a/src/Internal/Capabilities/Async.php b/src/Internal/Capabilities/Async.php index 780a22f..df286b6 100644 --- a/src/Internal/Capabilities/Async.php +++ b/src/Internal/Capabilities/Async.php @@ -38,9 +38,9 @@ public function streams(): Streams } #[\Override] - public function sockets(): Sockets + public function sockets(Files $files): Sockets { - return $this->capabilities->sockets(); + return $this->capabilities->sockets($files); } #[\Override] diff --git a/src/Internal/Capabilities/Implementation.php b/src/Internal/Capabilities/Implementation.php index ca8706b..3807ab3 100644 --- a/src/Internal/Capabilities/Implementation.php +++ b/src/Internal/Capabilities/Implementation.php @@ -12,6 +12,6 @@ interface Implementation { public function files(): Files; public function streams(): Streams; - public function sockets(): Sockets; + public function sockets(Files $files): Sockets; public function watch(): Watch; } diff --git a/src/Internal/Capabilities/Simulation.php b/src/Internal/Capabilities/Simulation.php index f461156..ec970cfa 100644 --- a/src/Internal/Capabilities/Simulation.php +++ b/src/Internal/Capabilities/Simulation.php @@ -43,9 +43,9 @@ public function streams(): Streams } #[\Override] - public function sockets(): Sockets + public function sockets(Files $files): Sockets { - return $this->capabilities->sockets(); + return $this->capabilities->sockets($files); } #[\Override] diff --git a/src/Internal/Capabilities/Sockets.php b/src/Internal/Capabilities/Sockets.php index 81c56c7..83b518c 100644 --- a/src/Internal/Capabilities/Sockets.php +++ b/src/Internal/Capabilities/Sockets.php @@ -14,16 +14,17 @@ */ final class Sockets { - private function __construct() - { + private function __construct( + private Files $files, + ) { } /** * @internal */ - public static function of(): self + public static function of(Files $files): self { - return new self; + return new self($files); } public function clients(): Sockets\Clients @@ -33,7 +34,7 @@ public function clients(): Sockets\Clients public function servers(): Sockets\Servers { - return Sockets\Servers::of(); + return Sockets\Servers::of($this->files); } /** diff --git a/src/Internal/Capabilities/Sockets/Servers.php b/src/Internal/Capabilities/Sockets/Servers.php index 6be6daa..20a37b9 100644 --- a/src/Internal/Capabilities/Sockets/Servers.php +++ b/src/Internal/Capabilities/Sockets/Servers.php @@ -10,6 +10,7 @@ Internal\Socket\Server, Internal\Socket\Server\Internet, Internal\Socket\Server\Unix, + Internal\Capabilities\Files, Exception\RuntimeException, }; use Innmind\IP\IP; @@ -21,16 +22,17 @@ */ final class Servers { - private function __construct() - { + private function __construct( + private Files $files, + ) { } /** * @internal */ - public static function of(): self + public static function of(Files $files): self { - return new self; + return new self($files); } /** @@ -93,10 +95,11 @@ public function takeOver(Address $path): Attempt { return $this ->unix($path) - ->recover(function() use ($path) { - @\unlink($path->toString()); - - return $this->unix($path); - }); + ->recover( + fn() => $this + ->files + ->remove($path->asPath()) + ->flatMap(fn() => $this->unix($path)), + ); } } diff --git a/src/Sockets/Unix/Address.php b/src/Sockets/Unix/Address.php index 20ae059..02a6fdf 100644 --- a/src/Sockets/Unix/Address.php +++ b/src/Sockets/Unix/Address.php @@ -23,6 +23,12 @@ public static function of(Path $path): self return new self($path); } + #[\NoDiscard] + public function asPath(): Path + { + return $this->path; + } + #[\NoDiscard] public function toString(): string {