protected function S3fsStreamWrapper::_write_cache in S3 File System 7.3
Same name and namespace in other branches
- 7 S3fsStreamWrapper.inc \S3fsStreamWrapper::_write_cache()
- 7.2 S3fsStreamWrapper.inc \S3fsStreamWrapper::_write_cache()
Write an object's (and its ancestor folders') metadata to the cache.
Parameters
array $metadata: An associative array of file metadata in this format: 'uri' => The full URI of the file, including the scheme. 'filesize' => The size of the file, in bytes. 'timestamp' => The file's create/update timestamp. 'dir' => A boolean indicating whether the object is a directory.
Throws
Exceptions which occur in the database call will percolate.
3 calls to S3fsStreamWrapper::_write_cache()
- S3fsStreamWrapper::mkdir in ./
S3fsStreamWrapper.inc - Support for mkdir().
- S3fsStreamWrapper::rename in ./
S3fsStreamWrapper.inc - S3fsStreamWrapper::writeUriToCache in ./
S3fsStreamWrapper.inc - Write the file at the given uri into the metadata cache.
File
- ./
S3fsStreamWrapper.inc, line 1051 - Drupal stream wrapper implementation for S3 File System.
Class
- S3fsStreamWrapper
- The stream wrapper class.
Code
protected function _write_cache($metadata) {
// Since public:///blah.jpg and public://blah.jpg refer to the same file
// (a file named blah.jpg at the root of the file system), we'll sometimes
// receive files with a /// in their URI. This messes with our caching
// scheme, though, so we need to remove the extra /.
if (strpos($metadata['uri'], 'public:///') === 0) {
$metadata['uri'] = preg_replace('^public://[/]+^', 'public://', $metadata['uri']);
}
elseif (strpos($metadata['uri'], 'private:///') === 0) {
$metadata['uri'] = preg_replace('^private://[/]+^', 'private://', $metadata['uri']);
}
db_merge('s3fs_file')
->key(array(
'uri' => $metadata['uri'],
))
->fields($metadata)
->execute();
$dirname = drupal_dirname($metadata['uri']);
// If this file isn't in the root directory, also write this file's
// ancestor folders to the cache.
if (file_uri_target($dirname) != '') {
$this
->mkdir($dirname, NULL, STREAM_MKDIR_RECURSIVE);
}
}