You are here

function _s3fs_convert_metadata in S3 File System 7.3

Same name and namespace in other branches
  1. 7 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: The uri of the resource.

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 A file metadata cache array.

5 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.
_s3fs_write_metadata in ./s3fs.module
Writes metadata to the temp table in the database.

File

./s3fs.module, line 651
Hook implementations and other primary functionality for S3 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' => REQUEST_TIME,
    'dir' => 0,
    'version' => '',
  );
  if (empty($s3_metadata)) {

    // The caller wants directory metadata.
    $metadata['dir'] = 1;
  }
  else {

    // The filesize value can come from either the Size or ContentLength
    // attribute, depending on which AWS API call built $s3_metadata.
    if (isset($s3_metadata['ContentLength'])) {
      $metadata['filesize'] = $s3_metadata['ContentLength'];
    }
    elseif (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['VersionId']) && $s3_metadata['VersionId'] != 'null') {
      $metadata['version'] = $s3_metadata['VersionId'];
    }
  }
  return $metadata;
}