From f328f53ec17a53efa3136c192dc035c731d94b7f Mon Sep 17 00:00:00 2001 From: Michael Gapczynski Date: Wed, 25 Jul 2012 16:54:46 -0400 Subject: [PATCH] Fix filesystem hash, no longer using basicOperation() Conflicts: lib/filesystemview.php --- apps/files_sharing/sharedstorage.php | 2 +- lib/filestorage.php | 2 +- lib/filestorage/common.php | 2 +- lib/filestorage/local.php | 2 +- lib/filesystem.php | 4 ++-- lib/filesystemview.php | 23 +++++++++++++++++++++-- 6 files changed, 27 insertions(+), 8 deletions(-) diff --git a/apps/files_sharing/sharedstorage.php b/apps/files_sharing/sharedstorage.php index d46a7d4e70a..41af077b5a9 100644 --- a/apps/files_sharing/sharedstorage.php +++ b/apps/files_sharing/sharedstorage.php @@ -456,7 +456,7 @@ class OC_Filestorage_Shared extends OC_Filestorage { } } - public function hash($type, $path, $raw) { + public function hash($type, $path, $raw = false) { $source = $this->getSource($path); if ($source) { $storage = OC_Filesystem::getStorage($source); diff --git a/lib/filestorage.php b/lib/filestorage.php index fd6497b9478..1a33d304630 100644 --- a/lib/filestorage.php +++ b/lib/filestorage.php @@ -45,7 +45,7 @@ abstract class OC_Filestorage{ abstract public function copy($path1,$path2); abstract public function fopen($path,$mode); abstract public function getMimeType($path); - abstract public function hash($type,$path,$raw); + abstract public function hash($type,$path,$raw = false); abstract public function free_space($path); abstract public function search($query); abstract public function touch($path, $mtime=null); diff --git a/lib/filestorage/common.php b/lib/filestorage/common.php index f0bfc064cb5..0d3e2c25fd6 100644 --- a/lib/filestorage/common.php +++ b/lib/filestorage/common.php @@ -110,7 +110,7 @@ abstract class OC_Filestorage_Common extends OC_Filestorage { unlink($tmpFile); return $mime; } - public function hash($type,$path,$raw){ + public function hash($type,$path,$raw = false){ $tmpFile=$this->getLocalFile(); $hash=hash($type,$tmpFile,$raw); unlink($tmpFile); diff --git a/lib/filestorage/local.php b/lib/filestorage/local.php index ea9a9070263..1f3fd2e9249 100644 --- a/lib/filestorage/local.php +++ b/lib/filestorage/local.php @@ -157,7 +157,7 @@ class OC_Filestorage_Local extends OC_Filestorage{ return $return; } - public function hash($type,$path,$raw){ + public function hash($type,$path,$raw = false){ return hash_file($type,$this->datadir.$path,$raw); } diff --git a/lib/filesystem.php b/lib/filesystem.php index 813590b00bb..2c7df5daa3c 100644 --- a/lib/filesystem.php +++ b/lib/filesystem.php @@ -458,8 +458,8 @@ class OC_Filesystem{ static public function getMimeType($path){ return self::$defaultInstance->getMimeType($path); } - static public function hash($type,$path){ - return self::$defaultInstance->hash($type,$path); + static public function hash($type,$path, $raw = false){ + return self::$defaultInstance->hash($type,$path, $raw); } static public function free_space($path='/'){ diff --git a/lib/filesystemview.php b/lib/filesystemview.php index c09f1de546a..f147cf5b244 100644 --- a/lib/filesystemview.php +++ b/lib/filesystemview.php @@ -366,8 +366,27 @@ class OC_FilesystemView { public function getMimeType($path){ return $this->basicOperation('getMimeType',$path); } - public function hash($type,$path){ - return $this->basicOperation('hash',$path,array('read')); + public function hash($type, $path, $raw = false) { + $absolutePath = $this->getAbsolutePath($path); + if (OC_FileProxy::runPreProxies('hash', $absolutePath) && OC_Filesystem::isValidPath($path)) { + $path = $this->getRelativePath($absolutePath); + if ($path == null) { + return false; + } + if (OC_Filesystem::$loaded && $this->fakeRoot == OC_Filesystem::getRoot()) { + OC_Hook::emit( + OC_Filesystem::CLASSNAME, + OC_Filesystem::signal_read, + array( OC_Filesystem::signal_param_path => $path) + ); + } + if ($storage = $this->getStorage($path)) { + $result = $storage->hash($type, $this->getInternalPath($path), $raw); + $result = OC_FileProxy::runPostProxies('hash', $absolutePath, $result); + return $result; + } + } + return null; } public function free_space($path='/'){ -- 2.39.5