includes/file.inc | 16 +++------------- includes/stream_wrappers.inc | 43 +++++++++++++++++++++++++++++++------------ 2 files changed, 34 insertions(+), 25 deletions(-) diff --git a/includes/file.inc b/includes/file.inc index ee6ce51..d72100f 100644 --- a/includes/file.inc +++ b/includes/file.inc @@ -2188,19 +2188,9 @@ function drupal_chmod($uri, $mode = NULL) { } } - // If this URI is a stream, pass it off to the appropriate stream wrapper. - // Otherwise, attempt PHP's chmod. This allows use of drupal_chmod even - // for unmanaged files outside of the stream wrapper interface. - if ($wrapper = file_stream_wrapper_get_instance_by_uri($uri)) { - if ($wrapper->chmod($mode)) { - return TRUE; - } - } - else { - if (@chmod($uri, $mode)) { - return TRUE; - } - } + if (@chmod($uri, $mode)) { + return TRUE; + } watchdog('file', 'The file permissions could not be set on %uri.', array('%uri' => $uri), WATCHDOG_ERROR); return FALSE; diff --git a/includes/stream_wrappers.inc b/includes/stream_wrappers.inc index 4882938..980e8cd 100644 --- a/includes/stream_wrappers.inc +++ b/includes/stream_wrappers.inc @@ -106,6 +106,7 @@ interface StreamWrapperInterface { public function stream_flush(); public function stream_tell(); public function stream_stat(); + public function stream_metadata($uri, $option, $value); public function unlink($uri); public function rename($from_uri, $to_uri); public function mkdir($uri, $mode, $options); @@ -185,7 +186,7 @@ interface DrupalStreamWrapperInterface extends StreamWrapperInterface { * @return * Returns TRUE on success or FALSE on failure. */ - public function chmod($mode); + // public function chmod($mode); /** * Returns canonical, absolute path of the resource. @@ -338,17 +339,6 @@ abstract class DrupalLocalStreamWrapper implements DrupalStreamWrapperInterface } /** - * Base implementation of chmod(). - */ - function chmod($mode) { - $output = @chmod($this->getLocalPath(), $mode); - // We are modifying the underlying file here, so we have to clear the stat - // cache so that PHP understands that URI has changed too. - clearstatcache(); - return $output; - } - - /** * Base implementation of realpath(). */ function realpath() { @@ -550,6 +540,35 @@ abstract class DrupalLocalStreamWrapper implements DrupalStreamWrapperInterface } /** + * {@inheritdoc} + */ + public function stream_metadata($uri, $option, $value) { + $target = $this->getLocalPath($uri); + $return = FALSE; + switch ($option) { + case STREAM_META_TOUCH: + if (!empty($value)) { + $return = touch($target, $value[0], $value[1]); + } + else { + $return = touch($target); + } + break; + + case STREAM_META_ACCESS: + $return = chmod($target, $value); + break; + } + if ($return) { + // For convenience clear the file status cache of the underlying file, + // since metadata operations are often followed by file status checks. + clearstatcache(TRUE, $target); + } + return $return; + } + + + /** * Support for unlink(). * * @param $uri