summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/filestorage.php58
-rw-r--r--settings/index.php9
-rw-r--r--settings/templates/index.php4
-rw-r--r--templates/installation.php18
4 files changed, 63 insertions, 26 deletions
diff --git a/lib/filestorage.php b/lib/filestorage.php
index fbd28a7dfb3..66b91fc19aa 100644
--- a/lib/filestorage.php
+++ b/lib/filestorage.php
@@ -92,13 +92,14 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
}
public function mkdir($path){
if($return=mkdir($this->datadir.$path)){
- $this->notifyObservers($path,OC_FILEACTION_CREATE);
+ $this->clearFolderSizeCache($path);
}
return $return;
}
public function rmdir($path){
if($return=rmdir($this->datadir.$path)){
$this->notifyObservers($path,OC_FILEACTION_DELETE);
+ $this->clearFolderSizeCache($path);
}
return $return;
}
@@ -170,6 +171,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
public function unlink($path){
if($return=unlink($this->datadir.$path)){
$this->notifyObservers($path,OC_FILEACTION_DELETE);
+ $this->clearFolderSizeCache($path);
}
return $return;
}
@@ -189,6 +191,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
}
if($return=copy($this->datadir.$path1,$this->datadir.$path2)){
$this->notifyObservers($path2,OC_FILEACTION_CREATE);
+ $this->clearFolderSizeCache($path);
}
return $return;
}
@@ -383,6 +386,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
if(rename($tmpFile,$this->datadir.$path)){
touch($this->datadir.$path, $fileStats['mtime'], $fileStats['atime']);
$this->notifyObservers($path,OC_FILEACTION_CREATE);
+ $this->clearFolderSizeCache($path);
return true;
}else{
return false;
@@ -394,6 +398,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
if(move_uploaded_file($tmpFile,$this->datadir.$path)){
touch($this->datadir.$path, $fileStats['mtime'], $fileStats['atime']);
$this->notifyObservers($path,OC_FILEACTION_CREATE);
+ $this->clearFolderSizeCache($path);
return true;
}else{
return false;
@@ -410,6 +415,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
if(is_file($dir.'/'.$item)){
if(unlink($dir.'/'.$item)){
$this->notifyObservers($dir.'/'.$item,OC_FILEACTION_DELETE);
+ $this->clearFolderSizeCache($path);
}
}elseif(is_dir($dir.'/'.$item)){
if (!$this->delTree($dirRelative. "/" . $item)){
@@ -419,6 +425,7 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
}
if($return=rmdir($dir)){
$this->notifyObservers($dir,OC_FILEACTION_DELETE);
+ $this->clearFolderSizeCache($path);
}
return $return;
}
@@ -481,24 +488,33 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
* @return int size of folder and it's content
*/
public function calculateFolderSize($path){
+ if($this->is_file($path)){
+ $path=dirname($path);
+ }
+ $path=str_replace('//','/',$path);
+ if($this->is_dir($path) and substr($path,-1)!='/'){
+ $path.='/';
+ }
+ error_log("calc: $path");
$size=0;
if ($dh = $this->opendir($path)) {
- while (($filename = readdir($dh)) !== false) {
- if($filename!='.' and $filename!='..'){
- $subFile=$path.'/'.$filename;
- if($this->is_file($subFile)){
- $size+=$this->filesize($subFile);
- }else{
- $size+=$this->calculateFolderSize($subFile);
- }
- }
- }
$query=OC_DB::prepare("SELECT size FROM *PREFIX*foldersize WHERE path=?");
$hasSize=$query->execute(array($path))->fetchAll();
if(count($hasSize)>0){// yes, update it
$query=OC_DB::prepare("UPDATE *PREFIX*foldersize SET size=? WHERE path=?");
$result=$query->execute(array($size,$path));
+ $size+=$hasSize[0]['size'];
}else{// no insert it
+ while (($filename = readdir($dh)) !== false) {
+ if($filename!='.' and $filename!='..'){
+ $subFile=$path.'/'.$filename;
+ if($this->is_file($subFile)){
+ $size+=$this->filesize($subFile);
+ }else{
+ $size+=$this->calculateFolderSize($subFile);
+ }
+ }
+ }
$query=OC_DB::prepare("INSERT INTO *PREFIX*foldersize VALUES(?,?)");
$result=$query->execute(array($path,$size));
}
@@ -511,13 +527,25 @@ class OC_FILESTORAGE_LOCAL extends OC_FILESTORAGE{
* @param string $path
*/
public function clearFolderSizeCache($path){
- $path=dirname($path);
+ if($this->is_file($path)){
+ $path=dirname($path);
+ }
+ $path=str_replace('//','/',$path);
+ if($this->is_dir($path) and substr($path,-1)!='/'){
+ $path.='/';
+ }
+ error_log($path);
$query=OC_DB::prepare("DELETE FROM *PREFIX*foldersize WHERE path = ?");
$result=$query->execute(array($path));
- if($path!='/'){
- $parts=explode('/');
- array_pop($parts);
+ if($path!='/' and $path!=''){
+ $parts=explode('/',$path);
+ //pop empty part
+ $part=array_pop($parts);
+ if(empty($part)){
+ array_pop($parts);
+ }
$parent=implode('/',$parts);
+ $this->clearFolderSizeCache($parent);
}
}
}
diff --git a/settings/index.php b/settings/index.php
index 31db326f6bc..521f2ade9da 100644
--- a/settings/index.php
+++ b/settings/index.php
@@ -8,7 +8,14 @@ if( !OC_USER::isLoggedIn()){
}
-$tmpl = new OC_TEMPLATE( "settings", "index", "admin" );
+$tmpl = new OC_TEMPLATE( "settings", "index", "admin");
+$used=OC_FILESYSTEM::filesize('/');
+$free=disk_free_space(OC_CONFIG::getValue('datadirectory'));
+$total=$free+$used;
+$relative=round(($used/$total)*100);
+$tmpl->assign('usage',OC_HELPER::humanFileSize($used));
+$tmpl->assign('total_space',OC_HELPER::humanFileSize($total));
+$tmpl->assign('usage_relative',$relative);
$tmpl->printPage();
?>
diff --git a/settings/templates/index.php b/settings/templates/index.php
index 910437fefc9..f3f0b533a62 100644
--- a/settings/templates/index.php
+++ b/settings/templates/index.php
@@ -1,8 +1,8 @@
<form id="quota">
<fieldset>
<legend>Account information</legend>
- <div id="quota_indicator"><div style="width:72%;">&nbsp;</div></div>
- <p>You're currently using 72% (7.2GB) of your 10GB space.</p>
+ <div id="quota_indicator"><div style="width:<?php echo $_['usage_relative'] ?>%;">&nbsp;</div></div>
+ <p>You're currently using <?php echo $_['usage_relative'] ?>% (<?php echo $_['usage'] ?>) of your <?php echo $_['total_space'] ?> space.</p>
</fieldset>
</form>
diff --git a/templates/installation.php b/templates/installation.php
index ca4ea0e5d24..be4693288b2 100644
--- a/templates/installation.php
+++ b/templates/installation.php
@@ -27,24 +27,26 @@
<p><label class="left">Database</label></p>
<p><input type="radio" name="dbtype" value='sqlite' id="sqlite" checked="checked" /><label for="sqlite">SQLite</label>
<input type="radio" name="dbtype" value='mysql' id="mysql"><label for="mysql">MySQL</label></p>
- <?php endif;?>
- <?php if($_['hasMySQL']): ?>
<div id="use_mysql">
- <p><input type="text" name="dbuser" value="admin / username" /></p>
- <p><input type="password" name="dbpass" value="password" /></p>
- <p><input type="text" name="dbname" value="database name" /></p>
+ <p><input type="text" name="dbuser" value="admin / username" /></p>
+ <p><input type="password" name="dbpass" value="password" /></p>
+ <p><input type="text" name="dbname" value="database name" /></p>
<?php endif;?>
<?php if($_['hasMySQL'] and !$_['hasSQLite']): ?>
- <input type='hidden' name='dbtype' value='mysql'/>
+ <input type='hidden' name='dbtype' value='mysql'/>
<?php endif;?>
<?php if(!$_['hasMySQL'] and $_['hasSQLite']): ?>
- <input type='hidden' name='dbtype' value='sqlite'/>
+ <input type='hidden' name='dbtype' value='sqlite'/>
<?php endif;?>
- <?php if($_['hasMySQL']): ?>
+ <?php if($_['hasMySQL'] and $_['hasSQLite']): ?>
<p><label class="left">Host</label></p><p><input type="text" name="dbhost" value="localhost" /></p>
<p><label class="left">Table prefix</label></p><p><input type="text" name="dbtableprefix" value="oc_" /></p>
</div>
<?php endif;?>
+ <?php if($_['hasMySQL'] and !$_['hasSQLite']): ?>
+ <p><label class="left">Host</label></p><p><input type="text" name="dbhost" value="localhost" /></p>
+ <p><label class="left">Table prefix</label></p><p><input type="text" name="dbtableprefix" value="oc_" /></p>
+ <?php endif;?>
</div>
</fieldset>
<fieldset>