diff --git a/core/lib/Drupal/Core/StreamWrapper/LocalReadOnlyStream.php b/core/lib/Drupal/Core/StreamWrapper/LocalReadOnlyStream.php index 49a6596..1b14280 100644 --- a/core/lib/Drupal/Core/StreamWrapper/LocalReadOnlyStream.php +++ b/core/lib/Drupal/Core/StreamWrapper/LocalReadOnlyStream.php @@ -12,8 +12,8 @@ * * This class extends the complete stream wrapper implementation in LocalStream. * URIs such as "public://example.txt" are expanded to a normal filesystem path - * such as "sites/default/files/example.txt" and then PHP filesystem functions are - * invoked. + * such as "sites/default/files/example.txt" and then PHP filesystem functions + * are invoked. * * Drupal\Core\StreamWrapper\LocalReadOnlyStream implementations need to * implement at least the getDirectoryPath() and getExternalUrl() methods. @@ -41,9 +41,7 @@ */ public function stream_open($uri, $mode, $options, &$opened_path) { if ($mode != "r") { - debug("Write mode detected."); if ($options & STREAM_REPORT_ERRORS) { - debug("Report errors detected."); trigger_error('stream_open() write modes not supported for read-only stream wrappers', E_USER_WARNING); } return FALSE; @@ -52,7 +50,7 @@ public function stream_open($uri, $mode, $options, &$opened_path) { $this->uri = $uri; $path = $this->getLocalPath(); $this->handle = ($options & STREAM_REPORT_ERRORS) ? fopen($path, $mode) : @fopen($path, $mode); - if ((bool) $this->handle && $options & STREAM_USE_PATH) { + if ($this->handle !== FALSE && ($options & STREAM_USE_PATH)) { $opened_path = $path; } @@ -70,21 +68,23 @@ public function stream_open($uri, $mode, $options, &$opened_path) { * - LOCK_SH to acquire a shared lock (reader). * - LOCK_EX to acquire an exclusive lock (writer). * - LOCK_UN to release a lock (shared or exclusive). - * - LOCK_NB if you don't want flock() to block while locking (not - * supported on Windows). + * - LOCK_NB added as a bitmask if you don't want flock() to block while + * locking (not supported on Windows). * * @return bool * Return FALSE for an exclusive lock (writer), as this is a read-only - * stream wrapper. Return TRUE for all other valid $operations. + * stream wrapper. Return the result of flock() for other valid operations. + * Defaults to TRUE if an invalid operation is passed. * * @see http://php.net/manual/streamwrapper.stream-lock.php */ public function stream_lock($operation) { - if (in_array($operation, array(LOCK_EX, LOCK_EX | LOCK_NB))) { + // Disallow exclusive lock or non-blocking lock requests + if (in_array($operation, array(LOCK_EX, LOCK_EX|LOCK_NB))) { trigger_error('stream_lock() exclusive lock operations not supported for read-only stream wrappers', E_USER_WARNING); return FALSE; } - if (in_array($operation, array(LOCK_SH, LOCK_UN, LOCK_NB))) { + if (in_array($operation, array(LOCK_SH, LOCK_UN, LOCK_SH|LOCK_NB))) { return flock($this->handle, $operation); } @@ -208,9 +208,15 @@ public function rmdir($uri, $options) { } /** - * Implements Drupal\Core\StreamWrapper\StreamWrapperInterface::chmod(). + * Support for chmod(). * * Does not change file permissions as this is a read-only stream wrapper. + * + * @param int $mode + * Permission flags - see chmod(). + * + * @return bool + * FALSE as the permission change will never be allowed. */ public function chmod($mode) { trigger_error('chmod() not supported for read-only stream wrappers', E_USER_WARNING); diff --git a/core/lib/Drupal/Core/StreamWrapper/ReadOnlyStream.php b/core/lib/Drupal/Core/StreamWrapper/ReadOnlyStream.php index 950ba34..2ebcc06 100644 --- a/core/lib/Drupal/Core/StreamWrapper/ReadOnlyStream.php +++ b/core/lib/Drupal/Core/StreamWrapper/ReadOnlyStream.php @@ -86,7 +86,7 @@ public function stream_open($uri, $mode, $options, &$opened_path) { $path = $this->getLocalPath(); $this->handle = ($options & STREAM_REPORT_ERRORS) ? fopen($path, $mode) : @fopen($path, $mode); - if ((bool) $this->handle && $options & STREAM_USE_PATH) { + if ($this->handle !== FALSE && ($options & STREAM_USE_PATH)) { $opened_path = $path; } @@ -109,16 +109,17 @@ public function stream_open($uri, $mode, $options, &$opened_path) { * * @return bool * Return FALSE for an exclusive lock (writer), as this is a read-only - * stream wrapper. Return TRUE for all other valid $operations. + * stream wrapper. Return the result of flock() for other valid operations. + * Defaults to TRUE if an invalid operation is passed. * * @see http://php.net/manual/streamwrapper.stream-lock.php */ public function stream_lock($operation) { - if (in_array($operation, array(LOCK_EX, LOCK_EX | LOCK_NB))) { + if (in_array($operation, array(LOCK_EX, LOCK_EX|LOCK_NB))) { trigger_error('stream_lock() exclusive lock operations not supported for read-only stream wrappers', E_USER_WARNING); return FALSE; } - if (in_array($operation, array(LOCK_SH, LOCK_UN, LOCK_NB))) { + if (in_array($operation, array(LOCK_SH, LOCK_UN, LOCK_SH|LOCK_NB))) { return flock($this->handle, $operation); } @@ -241,9 +242,15 @@ public function rmdir($uri, $options) { } /** - * Implements Drupal\Core\StreamWrapper\StreamWrapperInterface::chmod(). + * Support for chmod(). * * Does not change file permissions as this is a read-only stream wrapper. + * + * @param int $mode + * Permission flags - see chmod(). + * + * @return bool + * FALSE as the permission change will never be allowed. */ public function chmod($mode) { trigger_error('chmod() not supported for read-only stream wrappers', E_USER_WARNING);