[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [owncloud/sharing] apps/files_sharing: Update the folder sizes for
From:       Michael Gapczynski <GapczynskiM () gmail ! com>
Date:       2011-07-31 19:03:16
Message-ID: 20110731190316.34BC5A60A6 () git ! kde ! org
[Download RAW message or body]

Git commit c185743ae9e04f1bc6500ec570c40e9781fb4512 by Michael Gapczynski.
Committed on 31/07/2011 at 20:48.
Pushed by gapczynski into branch 'sharing'.

Update the folder sizes for shared folders

M  +29   -12   apps/files_sharing/sharedstorage.php

http://commits.kde.org/owncloud/c185743ae9e04f1bc6500ec570c40e9781fb4512

diff --git a/apps/files_sharing/sharedstorage.php \
b/apps/files_sharing/sharedstorage.php index 75767da..c819c6d 100644
--- a/apps/files_sharing/sharedstorage.php
+++ b/apps/files_sharing/sharedstorage.php
@@ -68,6 +68,7 @@ class OC_Filestorage_Shared extends OC_Filestorage {
 	public function rmdir($path) {
 		// The folder will be removed from the database, but won't be deleted \
from the owner's filesystem  \
OC_Share::unshareFromMySelf($this->datadir.$path); \
+		$this->clearFolderSizeCache($path);  }
 	
 	public function opendir($path) {
@@ -78,6 +79,7 @@ class OC_Filestorage_Shared extends OC_Filestorage {
 			if (empty($sharedItems)) {
 				return false;
 			}
+			$files = array();
 			foreach ($sharedItems as $item) {
 				// If item is in the root of the shared storage provider add it to the \
fakedirs  if (dirname($item['target'])."/" == $path) {
@@ -199,6 +201,7 @@ class OC_Filestorage_Shared extends OC_Filestorage {
 	}
 	
 	public function filesize($path) {
+		
 		if ($path == "" || $path == "/" || $this->is_dir($path)) {
 			return $this->getFolderSize($path);
 		} else {
@@ -211,12 +214,7 @@ class OC_Filestorage_Shared extends OC_Filestorage {
 	}
 	
 	public function getFolderSize($path) {
-		if ($path == "" || $path == "/") {
-			$dbpath = OC_User::getUser()."/files/Share/";
-		} else {
-			$source = $this->getSource($path);
-			$dbpath = $this->getInternalPath($source);
-		}
+		$dbpath = OC_User::getUser()."/files/Share/".$path."/";
 		$query = OC_DB::prepare("SELECT size FROM *PREFIX*foldersize WHERE \
path=?");  $size = $query->execute(array($dbpath))->fetchAll();
 		if (count($size) > 0) {
@@ -247,12 +245,7 @@ class OC_Filestorage_Shared extends OC_Filestorage {
 				}
 			}
 			if ($size > 0) {
-				if ($path == "" || $path == "/") {
-					$dbpath = OC_User::getUser()."/files/Share/";
-				} else {
-					$source = $this->getSource($path);
-					$dbpath = $this->getInternalPath($source);
-				}
+				$dbpath = OC_User::getUser()."/files/Share/".$path;
 				$query = OC_DB::prepare("INSERT INTO *PREFIX*foldersize VALUES(?,?)");
 				$result = $query->execute(array($dbpath, $size));
 			}
@@ -260,6 +253,27 @@ class OC_Filestorage_Shared extends OC_Filestorage {
 		return $size;
 	}
 
+	public function clearFolderSizeCache($path){
+		if ($this->is_file($path)) {
+			$path = dirname($path);
+		}
+		$path = str_replace("//", "/", $path);
+		if ($this->is_dir($path) && substr($path, -1) != "/") {
+			$path .= "/";
+		}
+		$query = OC_DB::prepare("DELETE FROM *PREFIX*foldersize WHERE path = \
?"); +		$result = $query->execute(array($path));
+		if ($path != "/" && $path != "") {
+			$parts = explode("/", $path);
+			$part = array_pop($parts);
+			if (empty($part)) {
+				array_pop($parts);
+			}
+			$parent = implode("/", $parts);
+			$this->clearFolderSizeCache($parent);
+		}
+	}
+
 	public function is_readable($path) {
 		return true;
 	}
@@ -397,6 +411,7 @@ class OC_Filestorage_Shared extends OC_Filestorage {
 			} else {
 				OC_Share::unshareFromMySelf($target);
 			}
+			$this->clearFolderSizeCache($this->getInternalPath($target));
 		}
 		return true;
 	}
@@ -423,6 +438,8 @@ class OC_Filestorage_Shared extends OC_Filestorage {
 					OC_Share::setTarget($oldTarget, $newTarget);
 				}
 			}
+			$this->clearFolderSizeCache($this->getInternalPath($oldTarget));
+			$this->clearFolderSizeCache($this->getInternalPath($newTarget));
 		}
 		return true;
 	}


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic