You are here

function _s3fs_convert_metadata in S3 File System 7

Same name and namespace in other branches
  1. 7.3 s3fs.module \_s3fs_convert_metadata()
  2. 7.2 s3fs.module \_s3fs_convert_metadata()

Convert file metadata returned from S3 into a metadata cache array.

Parameters

string $uri: A string containing the uri of the resource to check.

array $s3_metadata: An array containing the collective metadata for the object in S3. The caller may send an empty array here to indicate that the returned metadata should represent a directory.

Return value

array An array containing metadata formatted for the file metadata cache.

4 calls to _s3fs_convert_metadata()
S3fsStreamWrapper::mkdir in ./S3fsStreamWrapper.inc
Support for mkdir().
S3fsStreamWrapper::_get_metadata_from_s3 in ./S3fsStreamWrapper.inc
Returns the converted metadata for an object in S3.
S3fsStreamWrapper::_s3fs_get_object in ./S3fsStreamWrapper.inc
Try to fetch an object from the metadata cache.
_s3fs_refresh_cache in ./s3fs.module
Refreshes the metadata cache.

File

./s3fs.module, line 497
Sets up the S3fsStreamWrapper class to be used as a Drupal file system.

Code

function _s3fs_convert_metadata($uri, $s3_metadata) {

  // Need to fill in a default value for everything, so that DB calls
  // won't complain about missing fields.
  $metadata = array(
    'uri' => $uri,
    'filesize' => 0,
    'timestamp' => time(),
    'dir' => 0,
    // The S_IFREG posix flag, indicating a regular file.
    'mode' => 0100000,
    'uid' => '',
    'version' => '',
  );
  if (empty($s3_metadata)) {

    // The caller wants directory metadata.
    $metadata['dir'] = 1;
    $metadata['uid'] = 'S3 File System';

    // The posix S_IFDIR flag, indicating a directory.
    $metadata['mode'] = 040000;
  }
  else {

    // $s3_metadata describes an actual file.
    if (isset($s3_metadata['Size'])) {
      $metadata['filesize'] = $s3_metadata['Size'];
    }
    if (isset($s3_metadata['LastModified'])) {
      $metadata['timestamp'] = date('U', strtotime($s3_metadata['LastModified']));
    }
    if (isset($s3_metadata['Owner']['ID'])) {
      $metadata['uid'] = $s3_metadata['Owner']['ID'];
    }
    if (isset($s3_metadata['VersionId'])) {
      $metadata['version'] = $s3_metadata['VersionId'];
    }
  }

  // Everything is writeable.
  $metadata['mode'] |= 0777;
  return $metadata;
}