CC-323: Show appropriate error message if disk is full when attempting to upload files via the web UI

- Updated the StoreFile logic so it won't die while trying to copy a file, and instead pass error messages to the controller which can decide if it wants to die, which 	I've set ApiController and PluploadController todo on receipt of error code.
This commit is contained in:
Daniel 2012-02-14 18:12:29 -05:00
parent 9fc0ed198e
commit 14cd9ed0e9
3 changed files with 39 additions and 29 deletions

View File

@ -406,7 +406,10 @@ class ApiController extends Zend_Controller_Action
$tempFileName = basename($tempFilePath);
$fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : '';
Application_Model_StoredFile::copyFileToStor($upload_dir, $fileName, $tempFileName);
$result = Application_Model_StoredFile::copyFileToStor($upload_dir, $fileName, $tempFileName);
if (isset($result)){
die('{"jsonrpc" : "2.0", "error" : {"code": '.$result[code].', "message" : "'.$result[message].'"}}');
}
}
public function uploadRecordedAction()

View File

@ -38,8 +38,10 @@ class PluploadController extends Zend_Controller_Action
$upload_dir = ini_get("upload_tmp_dir") . DIRECTORY_SEPARATOR . "plupload";
$filename = $this->_getParam('name');
$tempname = $this->_getParam('tempname');
Application_Model_StoredFile::copyFileToStor($upload_dir, $filename, $tempname);
$result = Application_Model_StoredFile::copyFileToStor($upload_dir, $filename, $tempname);
if (isset($result)){
die('{"jsonrpc" : "2.0", "error" : {"code": '.$result[code].', "message" : "'.$result[message].'"}}');
}
die('{"jsonrpc" : "2.0"}');
}
}

View File

@ -851,11 +851,12 @@ class Application_Model_StoredFile {
$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."}}');
if ( $freeSpace < $fileSize){
$freeSpace = ceil($freeSpace/1024/1024);
$fileSize = ceil($fileSize/1024/1024);
$result = array("code" => 107, "message" => "The file was not uploaded, there is ".$freeSpace."MB of disk space left and the file you are uploading has a size of ".$fileSize."MB.");
}
return $result;
}
public static function copyFileToStor($p_targetDir, $fileName, $tempname){
@ -864,35 +865,39 @@ class Application_Model_StoredFile {
$md5 = md5_file($audio_file);
$duplicate = Application_Model_StoredFile::RecallByMd5($md5);
if ($duplicate) {
if (PEAR::isError($duplicate)) {
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": ' . $duplicate->getMessage() .'}}');
if (PEAR::isError($duplicate)) {
$result = array("code" => 105, "message" => $duplicate->getMessage());
}
if (file_exists($duplicate->getFilePath())) {
$duplicateName = $duplicate->getMetadataValue('MDATA_KEY_TITLE');
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "An identical audioclip named \"' . $duplicateName . '\" already exists on the server."}}');
$result = array( "code" => 106, "message" => "An identical audioclip named '$duplicateName' already exists on the server.");
}
}
$storDir = Application_Model_MusicDir::getStorDir();
$stor = $storDir->getDirectory();
//check to see if there is enough space in $stor to continue.
Application_Model_StoredFile::checkForEnoughDiskSpaceToCopy($stor, $audio_file);
if (!isset($result)){//The file has no duplicate, so procceed to copy.
$storDir = Application_Model_MusicDir::getStorDir();
$stor = $storDir->getDirectory();
//check to see if there is enough space in $stor to continue.
$result = Application_Model_StoredFile::checkForEnoughDiskSpaceToCopy($stor, $audio_file);
if (!isset($result)){//if result not set then there's enough disk space to copy the file over
$stor .= "/organize";
$audio_stor = $stor . DIRECTORY_SEPARATOR . $fileName;
Logging::log("copyFileToStor: moving file $audio_file to $audio_stor");
//Martin K.: changed to rename: Much less load + quicker since this is an atomic operation
$r = @rename($audio_file, $audio_stor);
$stor .= "/organize";
$audio_stor = $stor . DIRECTORY_SEPARATOR . $fileName;
Logging::log("copyFileToStor: moving file $audio_file to $audio_stor");
//Martin K.: changed to rename: Much less load + quicker since this is an atomic operation
$r = @rename($audio_file, $audio_stor);
if ($r === 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 from the organize after failed rename
die('{"jsonrpc" : "2.0", "error" : {"code": 101, "message": "The file was not uploaded, this error will occur if the computer hard drive does not have enough disk space."}}');
}
if ($r === 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 from the organize after failed rename
$result = array("code" => 108, "message" => "The file was not uploaded, this error will occur if the computer hard drive does not have enough disk space.");
}
}
}
return $result;
//$r = @copy($audio_file, $audio_stor);
//$r = @unlink($audio_file);
}