From 9fc0ed198e24f91248edcbfa777a45cbb4188058 Mon Sep 17 00:00:00 2001
From: Daniel <daniel@daniel-PC.(none)>
Date: Thu, 9 Feb 2012 12:45:39 -0500
Subject: [PATCH] CC-3230: Show appropriate error message if disk is full when
 attempting to upload files via the web UI

- moved the logic used to test that the destination folder has enought space to copy the given audio file into.
---
 airtime_mvc/application/models/StoredFile.php | 27 +++++++++++++------
 1 file changed, 19 insertions(+), 8 deletions(-)

diff --git a/airtime_mvc/application/models/StoredFile.php b/airtime_mvc/application/models/StoredFile.php
index b5285ca40..05a25abef 100644
--- a/airtime_mvc/application/models/StoredFile.php
+++ b/airtime_mvc/application/models/StoredFile.php
@@ -842,6 +842,22 @@ class Application_Model_StoredFile {
 		return $tempFilePath;
     }
 
+    /**
+     * Check, using disk_free_space, the space available in the $destination_folder folder to see if it has
+     * enough space to move the $audio_file into and report back to the user if not.
+     **/
+    public static function checkForEnoughDiskSpaceToCopy($destination_folder, $audio_file){
+	//check to see if we have enough space in the /organize directory to copy the file
+	$freeSpace = disk_free_space($destination_folder);
+	$fileSize = filesize($audio_file);
+	
+	if ( $freeSpace < $fileSize ){
+	    $freeSpace = floor($freeSpace/1024/1024);
+	    $fileSize = floor($fileSize/1024/1024);
+	    die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "The file was not uploaded, there was '.$freeSpace.'MB disk space left the file you are uploadings size is '.$fileSize.'MB."}}');
+	}
+    }
+    
     public static function copyFileToStor($p_targetDir, $fileName, $tempname){
         $audio_file = $p_targetDir . DIRECTORY_SEPARATOR . $tempname;
         Logging::log('copyFileToStor: moving file '.$audio_file);
@@ -860,14 +876,8 @@ class Application_Model_StoredFile {
         $storDir = Application_Model_MusicDir::getStorDir();
         $stor = $storDir->getDirectory();
 	
-	//check to see if we have enough space in the /organize directory to copy the file
-	$freeSpace = disk_free_space($stor);
-	$fileSize = filesize($audio_file);
-	if ( $freeSpace < $fileSize ){
-	    $freeSpace = floor($freeSpace/1024/1024);
-	    $fileSize = floor($fileSize/1024/1024);
-	    die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "The file was not uploaded, there was '.$freeSpace.'MB disk space left the file you are uploadings size is '.$fileSize.'MB."}}');
-	}
+	//check to see if there is enough space in $stor to continue.
+	Application_Model_StoredFile::checkForEnoughDiskSpaceToCopy($stor, $audio_file);
 	
         $stor .= "/organize";	
         $audio_stor = $stor . DIRECTORY_SEPARATOR . $fileName;	
@@ -887,6 +897,7 @@ class Application_Model_StoredFile {
         //$r = @unlink($audio_file);
     }
 
+    
     public static function getFileCount()
     {
 		global $CC_CONFIG, $CC_DBC;