move ETag generation to storage backends

This commit is contained in:
Robin Appelman 2012-11-08 17:47:00 +01:00
parent 72c3868644
commit 706bb3ccd6
5 changed files with 50 additions and 15 deletions

View File

@ -210,27 +210,13 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr
return $props;
}
/**
* Creates a ETag for this path.
* @param string $path Path of the file
* @return string|null Returns null if the ETag can not effectively be determined
*/
static protected function createETag($path) {
if(self::$ETagFunction) {
$hash = call_user_func(self::$ETagFunction, $path);
return $hash;
}else{
return uniqid('', true);
}
}
/**
* Returns the ETag surrounded by double-quotes for this path.
* @param string $path Path of the file
* @return string|null Returns null if the ETag can not effectively be determined
*/
static public function getETagPropertyForPath($path) {
$tag = self::createETag($path);
$tag = \OC\Files\Filesystem::getETag($path);
if (empty($tag)) {
return null;
}

View File

@ -654,6 +654,16 @@ class Filesystem {
public static function getDirectoryContent($directory, $mimetype_filter = '') {
return self::$defaultInstance->getDirectoryContent($directory, $mimetype_filter);
}
/**
* get the ETag for a file or folder
*
* @param string $path
* @return string
*/
static public function getETag($path){
return self::$defaultInstance->getETag($path);
}
}
\OC_Hook::connect('OC_Filesystem', 'post_write', 'OC_Filesystem', 'removeETagHook');

View File

@ -267,4 +267,20 @@ abstract class Common implements \OC\Files\Storage\Storage {
public function getOwner($path) {
return \OC_User::getUser();
}
/**
* get the ETag for a file or folder
*
* @param string $path
* @return string
*/
public function getETag($path){
$ETagFunction = \OC_Connector_Sabre_Node::$ETagFunction;
if($ETagFunction) {
$hash = call_user_func($ETagFunction, $path);
return $hash;
}else{
return uniqid('', true);
}
}
}

View File

@ -63,4 +63,12 @@ interface Storage{
public function getScanner();
public function getOwner($path);
/**
* get the ETag for a file or folder
*
* @param string $path
* @return string
*/
public function getETag($path);
}

View File

@ -866,4 +866,19 @@ class View {
return $files;
}
/**
* get the ETag for a file or folder
*
* @param string $path
* @return string
*/
public function getETag($path){
/**
* @var Storage\Storage $storage
* @var string $internalPath
*/
list($storage, $internalPath) = $this->resolvePath($path);
return $storage->getETag($internalPath);
}
}