Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PLAT-10752: Dismiss chunks that are of 0 bytes #9282

Merged
merged 2 commits into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions alpha/apps/kaltura/lib/exceptions/kUploadTokenException.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ class kUploadTokenException extends kCoreException
const UPLOAD_TOKEN_MAX_AUTO_FINALIZE_RETRIES_REACHED = "UPLOAD_TOKEN_MAX_AUTO_FINALIZE_RETRIES_REACHED";

const UPLOAD_TOKEN_AUTO_FINALIZE_CACHE_NOT_INITIALIZED = "UPLOAD_TOKEN_AUTO_FINALIZE_CACHE_NOT_INITIALIZED";

const UPLOAD_TOKEN_FILE_IS_EMPTY = "UPLOAD_TOKEN_FILE_IS_EMPTY";
}
20 changes: 18 additions & 2 deletions alpha/apps/kaltura/lib/kUploadTokenMgr.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,19 @@ public function uploadFileToToken($fileData, $resume = false, $resumeAt = -1)

try
{
$this->checkIfFileIsValid($fileData);
$this->checkIfFileIsValid($fileData, $resumeAt, $this->_finalChunk);
}
catch(kUploadTokenException $ex)
{
if($ex->getCode() == kUploadTokenException::UPLOAD_TOKEN_FILE_IS_EMPTY)
{
return;
}

if(!$resume && $this->_finalChunk)
{
kFlowHelper::handleUploadFailed($this->_uploadToken);
}

$this->tryMoveToErrors($fileData);
throw $ex;
Expand Down Expand Up @@ -147,7 +154,7 @@ public function deleteUploadToken()
* Validate the file data
* @param file $fileData
*/
protected function checkIfFileIsValid($fileData)
protected function checkIfFileIsValid($fileData, $resumeAt, $finalChunk)
{
// check file name
$fileName = isset($fileData['name']) ? $fileData['name'] : null;
Expand Down Expand Up @@ -175,6 +182,15 @@ protected function checkIfFileIsValid($fileData)
KalturaLog::log($msg . ' ' . print_r($fileData, true));
throw new kUploadTokenException($msg, kUploadTokenException::UPLOAD_TOKEN_FILE_IS_NOT_VALID);
}

$tempFileSize = kFile::fileSize($tempPath);
if($tempFileSize == 0 && !$finalChunk && $resumeAt > 0)
{
$msg = "The uploaded file has 0 bytes, file will be dismissed for token id [{$this->_uploadToken->getId()}]";
KalturaLog::log($msg . ' ' . print_r($fileData, true));
kFile::doDeleteFile($tempPath);
throw new kUploadTokenException($msg, kUploadTokenException::UPLOAD_TOKEN_FILE_IS_EMPTY);
}
}

/**
Expand Down