You are here

public function S3fsStreamWrapper::dir_opendir in S3 File System 7.2

Same name and namespace in other branches
  1. 7.3 S3fsStreamWrapper.inc \S3fsStreamWrapper::dir_opendir()
  2. 7 S3fsStreamWrapper.inc \S3fsStreamWrapper::dir_opendir()

Support for opendir().

Parameters

string $uri: The URI to the directory to open.

int $options: A flag used to enable safe_mode. This wrapper doesn't support safe_mode, so this parameter is ignored.

Return value

bool TRUE on success. Otherwise, FALSE.

Overrides StreamWrapperInterface::dir_opendir

See also

http://php.net/manual/en/streamwrapper.dir-opendir.php

File

./S3fsStreamWrapper.inc, line 1069
Drupal stream wrapper implementation for S3 File System.

Class

S3fsStreamWrapper
The stream wrapper class.

Code

public function dir_opendir($uri, $options = NULL) {
  $this
    ->_assert_constructor_called();
  $this
    ->_debug("dir_opendir({$uri}, {$options}) called.");
  if (!$this
    ->_uri_is_dir($uri)) {
    return FALSE;
  }
  $scheme = file_uri_scheme($uri);
  $bare_uri = rtrim($uri, '/');
  $slash_uri = $bare_uri . '/';

  // If this URI was originally a root folder (e.g. s3://), the above code
  // removed *both* slashes but only added one back. So we need to add
  // back the second slash.
  if ($slash_uri == "{$scheme}:/") {
    $slash_uri = "{$scheme}://";
  }

  // Get the list of uris for files and folders which are children of the
  // specified folder, but not grandchildren.
  $child_uris = db_select('s3fs_file', 's')
    ->fields('s', array(
    'uri',
  ))
    ->condition('uri', db_like($slash_uri) . '%', 'LIKE')
    ->condition('uri', db_like($slash_uri) . '%/%', 'NOT LIKE')
    ->execute()
    ->fetchCol(0);
  $this->dir = array();
  foreach ($child_uris as $child_uri) {
    $this->dir[] = drupal_basename($child_uri);
  }
  return TRUE;
}