Example #1
0
 public static function GetDiskInfo()
 {
     $partions = array();
     if (isset($_SERVER['AIRTIME_SRV'])) {
         //connect to DB and find how much total space user has allocated.
         $totalSpace = Application_Model_Preference::GetDiskQuota();
         $storPath = Application_Model_MusicDir::getStorDir()->getDirectory();
         list($usedSpace, ) = preg_split("/[\\s]+/", exec("du -bs {$storPath}"));
         $partitions[$totalSpace]->totalSpace = $totalSpace;
         $partitions[$totalSpace]->totalFreeSpace = $totalSpace - $usedSpace;
         Logging::info($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);
 }
 public function updateFileSystemMountAction()
 {
     $request = $this->getRequest();
     $params = $request->getParams();
     $added_list = empty($params['added_dir']) ? array() : explode(',', $params['added_dir']);
     $removed_list = empty($params['removed_dir']) ? array() : explode(',', $params['removed_dir']);
     // get all watched dirs
     $watched_dirs = Application_Model_MusicDir::getWatchedDirs(null, null);
     foreach ($added_list as $ad) {
         $ad .= '/';
         foreach ($watched_dirs as $dir) {
             $dirPath = $dir->getDirectory();
             // if mount path itself was watched
             if ($dirPath == $ad) {
                 Application_Model_MusicDir::addWatchedDir($dirPath, false);
             } elseif (substr($dirPath, 0, strlen($ad)) === $ad && $dir->getExistsFlag() == false) {
                 // if dir contains any dir in removed_list( if watched dir resides on new mounted path )
                 Application_Model_MusicDir::addWatchedDir($dirPath, false);
             } elseif (substr($ad, 0, strlen($dirPath)) === $dirPath) {
                 // is new mount point within the watched dir?
                 // pyinotify doesn't notify anyhing in this case, so we add this mount point as
                 // watched dir
                 // bypass nested loop check
                 Application_Model_MusicDir::addWatchedDir($ad, false, true);
             }
         }
     }
     foreach ($removed_list as $rd) {
         $rd .= '/';
         foreach ($watched_dirs as $dir) {
             $dirPath = $dir->getDirectory();
             // if dir contains any dir in removed_list( if watched dir resides on new mounted path )
             if (substr($dirPath, 0, strlen($rd)) === $rd && $dir->getExistsFlag() == true) {
                 Application_Model_MusicDir::removeWatchedDir($dirPath, false);
             } elseif (substr($rd, 0, strlen($dirPath)) === $dirPath) {
                 // is new mount point within the watched dir?
                 // pyinotify doesn't notify anyhing in this case, so we walk through all files within
                 // this watched dir in DB and mark them deleted.
                 // In case of h) of use cases, due to pyinotify behaviour of noticing mounted dir, we need to
                 // compare agaisnt all files in cc_files table
                 $watchDir = Application_Model_MusicDir::getDirByPath($rd);
                 // get all the files that is under $dirPath
                 $files = Application_Model_StoredFile::listAllFiles($dir->getId(), $all = false);
                 foreach ($files as $f) {
                     // if the file is from this mount
                     if (substr($f->getFilePath(), 0, strlen($rd)) === $rd) {
                         $f->delete();
                     }
                 }
                 if ($watchDir) {
                     Application_Model_MusicDir::removeWatchedDir($rd, false);
                 }
             }
         }
     }
 }
 public static function GetDiskInfo()
 {
     $partitions = array();
     /* 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);
 }