From 706bb3ccd654f76c0a6c5b7874fcc1e288b13f54 Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind@owncloud.com>
Date: Thu, 8 Nov 2012 17:47:00 +0100
Subject: [PATCH] move ETag generation to storage backends

---
 lib/connector/sabre/node.php  | 16 +---------------
 lib/files/filesystem.php      | 10 ++++++++++
 lib/files/storage/common.php  | 16 ++++++++++++++++
 lib/files/storage/storage.php |  8 ++++++++
 lib/files/view.php            | 15 +++++++++++++++
 5 files changed, 50 insertions(+), 15 deletions(-)

diff --git a/lib/connector/sabre/node.php b/lib/connector/sabre/node.php
index ebc9e53962..d0ab0c2498 100644
--- a/lib/connector/sabre/node.php
+++ b/lib/connector/sabre/node.php
@@ -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;
 		}
diff --git a/lib/files/filesystem.php b/lib/files/filesystem.php
index 76a188e412..ed2814211f 100644
--- a/lib/files/filesystem.php
+++ b/lib/files/filesystem.php
@@ -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');
diff --git a/lib/files/storage/common.php b/lib/files/storage/common.php
index e22264d0da..f471752d1f 100644
--- a/lib/files/storage/common.php
+++ b/lib/files/storage/common.php
@@ -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);
+		}
+	}
 }
diff --git a/lib/files/storage/storage.php b/lib/files/storage/storage.php
index 1f5c935629..bb1ba16984 100644
--- a/lib/files/storage/storage.php
+++ b/lib/files/storage/storage.php
@@ -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);
 }
diff --git a/lib/files/view.php b/lib/files/view.php
index e3f9b762f7..a54c3ee356 100644
--- a/lib/files/view.php
+++ b/lib/files/view.php
@@ -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);
+	}
 }
-- 
GitLab