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

- Updated the code to get the remaining free disk space and compare it to the size of the file to be uploaded and notify the user if the file is larger then diskspace.
This commit is contained in:
Daniel 2012-02-08 17:56:26 -05:00
parent c6addf37ba
commit cdc72beb6b
1 changed files with 15 additions and 8 deletions

View File

@ -859,21 +859,28 @@ class Application_Model_StoredFile {
$storDir = Application_Model_MusicDir::getStorDir();
$stor = $storDir->getDirectory();
$stor .= "/organize";
$audio_stor = $stor . DIRECTORY_SEPARATOR . $fileName;
//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."}}');
}
$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.
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."}}');
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."}}');
}
//$r = @copy($audio_file, $audio_stor);