public static function copyFileToStor($p_targetDir, $fileName, $tempname) { $audio_file = $p_targetDir . DIRECTORY_SEPARATOR . $tempname; Logging::info('copyFileToStor: moving file ' . $audio_file); $storDir = Application_Model_MusicDir::getStorDir(); $stor = $storDir->getDirectory(); // check if "organize" dir exists and if not create one if (!file_exists($stor . "/organize")) { if (!mkdir($stor . "/organize", 0777)) { return array("code" => 109, "message" => "Failed to create 'organize' directory."); } } if (chmod($audio_file, 0644) === false) { Logging::info("Warning: couldn't change permissions of {$audio_file} to 0644"); } // Check if we have enough space before copying if (!self::isEnoughDiskSpaceToCopy($stor, $audio_file)) { $freeSpace = disk_free_space($stor); return array("code" => 107, "message" => "The file was not uploaded, there is\n " . $freeSpace . "MB of disk space left and the file you are\n uploading has a size of " . $fileSize . "MB."); } // Check if liquidsoap can play this file if (!self::liquidsoapFilePlayabilityTest($audio_file)) { return array("code" => 110, "message" => "This file appears to be corrupted and will not\n be added to media library."); } // Did all the checks for real, now trying to copy $audio_stor = Application_Common_OsPath::join($stor, "organize", $fileName); $user = Application_Model_User::getCurrentUser(); if (is_null($user)) { $uid = Application_Model_User::getFirstAdminId(); } else { $uid = $user->getId(); } $id_file = "{$audio_stor}.identifier"; if (file_put_contents($id_file, $uid) === false) { Logging::info("Could not write file to identify user: '******'"); Logging::info("Id file path: '{$id_file}'"); Logging::info("Defaulting to admin (no identification file was\n written)"); } else { Logging::info("Successfully written identification file for\n uploaded '{$audio_stor}'"); } Logging::info("copyFileToStor: moving file {$audio_file} to {$audio_stor}"); // Martin K.: changed to rename: Much less load + quicker since this is // an atomic operation if (@rename($audio_file, $audio_stor) === false) { //something went wrong likely there wasn't enough space in . //the audio_stor to move the file too warn the user that . //the file wasn't uploaded and they should check if there . //is enough disk space . unlink($audio_file); //remove the file after failed rename unlink($id_file); // Also remove the identifier file return array("code" => 108, "message" => "\n The file was not uploaded, this error can occur if the computer\n hard drive does not have enough disk space or the stor\n directory does not have correct write permissions."); } // Now that we successfully added this file, we will add another tag // file that will identify the user that owns it return null; }
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 listAllWatchedDirsAction() { $result = array(); $arrWatchedDirs = Application_Model_MusicDir::getWatchedDirs(); $storDir = Application_Model_MusicDir::getStorDir(); $result[$storDir->getId()] = $storDir->getDirectory(); foreach ($arrWatchedDirs as $watchedDir) { $result[$watchedDir->getId()] = $watchedDir->getDirectory(); } $this->view->dirs = $result; }
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); }