You are here

public function S3fsStream::mkdir in S3 File System 8.2

Same name and namespace in other branches
  1. 8.3 src/StreamWrapper/S3fsStream.php \Drupal\s3fs\StreamWrapper\S3fsStream::mkdir()
  2. 4.0.x src/StreamWrapper/S3fsStream.php \Drupal\s3fs\StreamWrapper\S3fsStream::mkdir()

Support for mkdir().

Parameters

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

int $mode: Permission flags - see mkdir().

int $options: A bit mask of STREAM_REPORT_ERRORS and STREAM_MKDIR_RECURSIVE.

Return value

bool TRUE if the directory was successfully created. Otherwise, FALSE.

Overrides PhpStreamWrapperInterface::mkdir

See also

http://php.net/manual/en/streamwrapper.mkdir.php

1 call to S3fsStream::mkdir()
S3fsStream::_write_cache in src/StreamWrapper/S3fsStream.php
Write an object's (and its ancestor folders') metadata to the cache.

File

src/StreamWrapper/S3fsStream.php, line 940

Class

S3fsStream
Defines a Drupal s3fs (s3fs://) stream wrapper class.

Namespace

Drupal\s3fs\StreamWrapper

Code

public function mkdir($uri, $mode, $options) {
  $this
    ->_assert_constructor_called();
  $this
    ->_debug("mkdir({$uri}, {$mode}, {$options}) called.");
  clearstatcache(TRUE, $uri);

  // If this URI already exists in the cache, return TRUE if it's a folder
  // (so that recursive calls won't improperly report failure when they
  // reach an existing ancestor), or FALSE if it's a file (failure).
  $test_metadata = $this
    ->_read_cache($uri);
  if ($test_metadata) {
    return (bool) $test_metadata['dir'];
  }
  $metadata = $this
    ->convertMetadata($uri, []);
  $this
    ->_write_cache($metadata);

  // If the STREAM_MKDIR_RECURSIVE option was specified, also create all the
  // ancestor folders of this uri, except for the root directory.
  $parent_dir = \Drupal::service('file_system')
    ->dirname($uri);
  if ($options & STREAM_MKDIR_RECURSIVE && file_uri_target($parent_dir) != '') {
    return $this
      ->mkdir($parent_dir, $mode, $options);
  }
  return TRUE;
}