public function S3fsStreamWrapper::rmdir in S3 File System 7.3
Same name and namespace in other branches
- 7 S3fsStreamWrapper.inc \S3fsStreamWrapper::rmdir()
- 7.2 S3fsStreamWrapper.inc \S3fsStreamWrapper::rmdir()
Support for rmdir().
Parameters
string $uri: The URI to the folder to delete.
int $options: A bit mask of STREAM_REPORT_ERRORS.
Return value
bool TRUE if folder is successfully removed. FALSE if $uri isn't a folder, or the folder is not empty.
Overrides StreamWrapperInterface::rmdir
See also
http://php.net/manual/en/streamwrapper.rmdir.php
File
- ./
S3fsStreamWrapper.inc, line 800 - Drupal stream wrapper implementation for S3 File System.
Class
- S3fsStreamWrapper
- The stream wrapper class.
Code
public function rmdir($uri, $options) {
if (!$this
->_path_is_dir($uri)) {
return FALSE;
}
// We need a version of $uri with no / because folders are cached with no /.
// We also need one with the /, because it might be a file in S3 that
// ends with /. In addition, we must differentiate against files with this
// folder's name as a substring.
// e.g. rmdir('s3://foo/bar') should ignore s3://foo/barbell.jpg.
$bare_path = rtrim($uri, '/');
$slash_path = $bare_path . '/';
// If the folder is empty, it's eligible for deletion.
$file_count = db_select('s3fs_file', 's')
->fields('s')
->condition('uri', db_like($slash_path) . '%', 'LIKE')
->execute()
->rowCount();
if ($file_count === 0) {
if (parent::rmdir($this
->convertUriToKeyedPath($uri), $options)) {
$this
->_delete_cache($uri);
clearstatcache(TRUE, $uri);
return TRUE;
}
}
// The folder is non-empty.
return FALSE;
}