From 7247f75563af3392debf12e410bdead9dd5d50c3 Mon Sep 17 00:00:00 2001 From: Martin Konecny Date: Wed, 4 Jan 2012 14:18:40 -0500 Subject: [PATCH] SAAS-135: Airtime status page reporting free space being incorrectly for Gluster FS mounts -Done --- airtime_mvc/application/models/Preference.php | 12 +++++ .../application/models/Systemstatus.php | 45 ++++++++++++------- 2 files changed, 41 insertions(+), 16 deletions(-) diff --git a/airtime_mvc/application/models/Preference.php b/airtime_mvc/application/models/Preference.php index e3ec20b62..3e77a93d8 100644 --- a/airtime_mvc/application/models/Preference.php +++ b/airtime_mvc/application/models/Preference.php @@ -680,6 +680,18 @@ class Application_Model_Preference return $val; } + public static function SetDiskQuota($value){ + self::SetValue("disk_quota", $value, false); + } + + public static function GetDiskQuota(){ + $val = self::GetValue("disk_quota"); + if(strlen($val) == 0) { + $val = "0"; + } + return $val; + } + /* User specific preferences end */ } diff --git a/airtime_mvc/application/models/Systemstatus.php b/airtime_mvc/application/models/Systemstatus.php index bf8c7264d..388cdb846 100644 --- a/airtime_mvc/application/models/Systemstatus.php +++ b/airtime_mvc/application/models/Systemstatus.php @@ -184,24 +184,37 @@ class Application_Model_Systemstatus } public static function GetDiskInfo(){ - /* First lets get all the watched directories. Then we can group them - * into the same paritions by comparing the partition sizes. */ - $musicDirs = Application_Model_MusicDir::getWatchedDirs(); - $musicDirs[] = Application_Model_MusicDir::getStorDir(); - - $partions = array(); - - foreach($musicDirs as $md){ - $totalSpace = disk_total_space($md->getDirectory()); - - if (!isset($partitions[$totalSpace])){ - $partitions[$totalSpace] = new StdClass; - $partitions[$totalSpace]->totalSpace = $totalSpace; - $partitions[$totalSpace]->totalFreeSpace = disk_free_space($md->getDirectory()); - } + + if (isset($_SERVER['AIRTIME_SRV'])){ + //connect to DB and find how much total space user has allocated. + $totalSpace = Application_Model_Preference::GetDiskQuota(); - $partitions[$totalSpace]->dirs[] = $md->getDirectory(); + $storPath = Application_Model_MusicDir::getStorDir()->getDirectory(); + + list($usedSpace,) = preg_split("/[\s]+/", exec("du -s $storPath")); + + $partitions[$totalSpace]->totalSpace = $totalSpace; + $partitions[$totalSpace]->totalFreeSpace = $totalSpace - $usedSpace; + Logging::log($partitions[$totalSpace]->totalFreeSpace); + } else { + /* First lets get all the watched directories. Then we can group them + * into the same partitions by comparing the partition sizes. */ + $musicDirs = Application_Model_MusicDir::getWatchedDirs(); + $musicDirs[] = Application_Model_MusicDir::getStorDir(); + + foreach($musicDirs as $md){ + $totalSpace = disk_total_space($md->getDirectory()); + + if (!isset($partitions[$totalSpace])){ + $partitions[$totalSpace] = new StdClass; + $partitions[$totalSpace]->totalSpace = $totalSpace; + $partitions[$totalSpace]->totalFreeSpace = disk_free_space($md->getDirectory()); + + } + + $partitions[$totalSpace]->dirs[] = $md->getDirectory(); + } } return array_values($partitions);