You are here

public function S3fsStreamWrapper::mkdir in S3 File System 7.3

Same name and namespace in other branches
  1. 7 S3fsStreamWrapper.inc \S3fsStreamWrapper::mkdir()
  2. 7.2 S3fsStreamWrapper.inc \S3fsStreamWrapper::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 StreamWrapperInterface::mkdir

See also

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

1 call to S3fsStreamWrapper::mkdir()
S3fsStreamWrapper::_write_cache in ./S3fsStreamWrapper.inc
Write an object's (and its ancestor folders') metadata to the cache.

File

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

Class

S3fsStreamWrapper
The stream wrapper class.

Code

public function mkdir($uri, $mode, $options) {

  // Some Drupal plugins call mkdir with a trailing slash. We mustn't store
  // that slash in the cache.
  $uri = rtrim($uri, '/');
  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'];
  }

  // S3 is a flat file system, with no concept of directories (just files
  // with slashes in their names). We store folders in the metadata cache,
  // but don't create an object for them in S3.
  $metadata = _s3fs_convert_metadata($uri, array());
  $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_dirname($uri);
  if ($options & STREAM_MKDIR_RECURSIVE && file_uri_target($parent_dir) != '') {
    return $this
      ->mkdir($parent_dir, $mode, $options);
  }
  return TRUE;
}