diff options
author | Bart Visscher <bartv@thisnet.nl> | 2012-07-20 23:52:47 +0200 |
---|---|---|
committer | Bart Visscher <bartv@thisnet.nl> | 2012-07-21 00:13:30 +0200 |
commit | cdd9ffc8a5dba2d4c3d83d77fc7806fd017a6b97 (patch) | |
tree | 2c3fcc226540001e0df178fdb7e3b0e029c814e5 /lib/connector/sabre/node.php | |
parent | 53bdb049cb3d2b005e5f6d17117f878b74aa0194 (diff) | |
download | nextcloud-server-cdd9ffc8a5dba2d4c3d83d77fc7806fd017a6b97.tar.gz nextcloud-server-cdd9ffc8a5dba2d4c3d83d77fc7806fd017a6b97.zip |
Add ETag support to the Sabre file connector.
This is based on the md5 of the file, can be changed later
Diffstat (limited to 'lib/connector/sabre/node.php')
-rw-r--r-- | lib/connector/sabre/node.php | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/lib/connector/sabre/node.php b/lib/connector/sabre/node.php index be315a0ffd9..5bb92922f8f 100644 --- a/lib/connector/sabre/node.php +++ b/lib/connector/sabre/node.php @@ -22,6 +22,7 @@ */ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IProperties { + const GETETAG_PROPERTYNAME = '{DAV:}getetag'; /** * The path to the current node @@ -200,4 +201,29 @@ abstract class OC_Connector_Sabre_Node implements Sabre_DAV_INode, Sabre_DAV_IPr } return $props; } + + /** + * 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 getETagPropertyForFile($path) { + $tag = OC_Filesystem::hash('md5', $path); + if (empty($tag)) { + return null; + } + $etag = '"'.$tag.'"'; + $query = OC_DB::prepare( 'INSERT INTO *PREFIX*properties (userid,propertypath,propertyname,propertyvalue) VALUES(?,?,?,?)' ); + $query->execute( array( OC_User::getUser(), $path, self::GETETAG_PROPERTYNAME, $etag )); + return $etag; + } + + /** + * Remove the ETag from the cache. + * @param string $path Path of the file + */ + static public function removeETagPropertyForFile($path) { + $query = OC_DB::prepare( 'DELETE FROM *PREFIX*properties WHERE userid = ? AND propertypath = ? AND propertyname = ?' ); + $query->execute( array( OC_User::getUser(), $path, self::GETETAG_PROPERTYNAME )); + } } |