public function S3fsStreamWrapper::rename in S3 File System 7
Same name and namespace in other branches
- 7.3 S3fsStreamWrapper.inc \S3fsStreamWrapper::rename()
- 7.2 S3fsStreamWrapper.inc \S3fsStreamWrapper::rename()
Support for rename().
If $to_uri exists, this file will be overwritten. This behavior is identical to the PHP rename() function.
Parameters
string $from_uri: The uri to the file to rename.
string $to_uri: The new uri for file.
Return value
bool TRUE if file was successfully renamed.
Overrides StreamWrapperInterface::rename
See also
http://php.net/manual/en/streamwrapper.rename.php
File
- ./
S3fsStreamWrapper.inc, line 813 - Drupal stream wrapper implementation for S3 File System.
Class
- S3fsStreamWrapper
- The stream wrapper class.
Code
public function rename($from_uri, $to_uri) {
$this
->_assert_constructor_called();
$this
->_debug("rename({$from_uri}, {$to_uri}) called.");
$from_params = $this
->_get_params($from_uri);
$to_params = $this
->_get_params($to_uri);
clearstatcache(TRUE, $from_uri);
clearstatcache(TRUE, $to_uri);
// Add the copyObject() parameters.
$to_params['CopySource'] = "/{$from_params['Bucket']}/" . rawurlencode($from_params['Key']);
$to_params['MetadataDirective'] = 'COPY';
$to_params['ACL'] = 'public-read';
try {
// Copy the original object to the specified destination.
$this->s3
->copyObject($to_params);
// Copy the original object's metadata.
$metadata = $this
->_read_cache($from_uri);
$metadata['uri'] = $to_uri;
$this
->_write_cache($metadata);
// We need to wait because of S3's "eventual consistency".
$wait_params = $this
->_get_params($to_uri);
$wait_params['waiter.interval'] = 2;
$this->s3
->waitUntilObjectExists($wait_params);
// Now that we know the new object is there, delete the old one.
return $this
->unlink($from_uri);
} catch (\Exception $e) {
$this
->_debug($e
->getMessage());
return $this
->_trigger_error($e
->getMessage());
}
}