Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/treetrek.git

Fixes handle type mismatch

AuthorDave Jarvis <email>
Date2026-02-21 17:18:29 GMT-0800
Commit28158da3e9313d07e14fb6bf1bd97c4943ee395a
Parent03e4a1a
git/BufferedReader.php
private mixed $handle;
private bool $temporary;
+ private bool $owned;
- private function __construct( mixed $handle, bool $temporary ) {
+ private function __construct( mixed $handle, bool $temporary, bool $owned = true ) {
$this->handle = $handle;
$this->temporary = $temporary;
+ $this->owned = $owned;
}
public static function open( string $path ): self {
return new self( @fopen( $path, 'rb' ), false );
}
public static function createTemp(): self {
return new self( @tmpfile(), true );
+ }
+
+ public static function wrap( mixed $handle ): self {
+ return new self( $handle, false, false );
}
public function isOpen(): bool {
return is_resource( $this->handle );
}
public function __destruct() {
- $this->isOpen() ? fclose( $this->handle ) : null;
+ $this->owned && $this->isOpen() ? fclose( $this->handle ) : null;
}
git/FileHandlePool.php
<?php
+require_once __DIR__ . '/BufferedReader.php';
class FileHandlePool {
private array $handles;
if( array_key_exists( $path, $this->handles ) ) {
- $result = $action( $this->handles[$path] );
+ $result = $action( BufferedReader::wrap( $this->handles[$path] ) );
}
Delta10 lines added, 3 lines removed, 7-line increase