From cb0666e23595cddd40c3fc27abaa139fca71411b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= Date: Wed, 14 Nov 2012 15:34:52 +0100 Subject: [PATCH] move the identification of the real path of a shared file to the filecache --- apps/files/ajax/upload.php | 15 ++------------- lib/filecache.php | 24 ++++++++++++++++++++++++ 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/apps/files/ajax/upload.php b/apps/files/ajax/upload.php index 3a3d874cfa..a4dcd80a2e 100644 --- a/apps/files/ajax/upload.php +++ b/apps/files/ajax/upload.php @@ -49,19 +49,8 @@ if(strpos($dir, '..') === false) { for($i=0;$i<$fileCount;$i++) { $target = OCP\Files::buildNotExistingFileName(stripslashes($dir), $files['name'][$i]); if(is_uploaded_file($files['tmp_name'][$i]) and OC_Filesystem::fromTmpFile($files['tmp_name'][$i], $target)) { - if ( OC_App::isEnabled('files_sharing') && !strncmp($target, '/Shared/', 8)) { - $source = OC_Files_Sharing_Util::getSourcePath(str_replace('/Shared/', '', $target)); - $parts = explode('/', $source, 4); - $root = '/'.$parts[1].'/files'; - $path = '/'.$parts[3]; - } else { - $path = $target; - $root = false; - } - - $meta = OC_FileCache::get($path, $root); - $id = OC_FileCache::getId($path, $root); - + $meta = OC_FileCache::get($target); + $id = OC_FileCache::getId($target); $result[]=array( "status" => "success", 'mime'=>$meta['mimetype'],'size'=>$meta['size'], 'id'=>$id, 'name'=>basename($target)); } } diff --git a/lib/filecache.php b/lib/filecache.php index 40d6302127..5fa32fb829 100644 --- a/lib/filecache.php +++ b/lib/filecache.php @@ -43,6 +43,9 @@ class OC_FileCache{ * - versioned */ public static function get($path,$root=false) { + + list($path, $root) = self::getSourcePathOfSharedFile($path); + if(OC_FileCache_Update::hasUpdated($path,$root)) { if($root===false) {//filesystem hooks are only valid for the default root OC_Hook::emit('OC_Filesystem','post_write',array('path'=>$path)); @@ -277,6 +280,9 @@ class OC_FileCache{ * @return int */ public static function getId($path,$root=false) { + + list($path, $root) = self::getSourcePathOfSharedFile($path); + if($root===false) { $root=OC_Filesystem::getRoot(); } @@ -507,6 +513,24 @@ class OC_FileCache{ $query->execute(array('httpd/unix-directory')); } } + + /** + * get the real path and the root of a shared file + * @param string $path + * @return array with the path and the root of the give file + */ + private static function getSourcePathOfSharedFile($path) { + if ( OC_App::isEnabled('files_sharing') && !strncmp($path, '/Shared/', 8)) { + $source = OC_Files_Sharing_Util::getSourcePath(str_replace('/Shared/', '', $path)); + $parts = explode('/', $source, 4); + $root = '/'.$parts[1].'/files'; + $path = '/'.$parts[3]; + } else { + $root = false; + } + + return array($path, $root); + } } //watch for changes and try to keep the cache up to date