add file open and write error handling

This commit is contained in:
Stephen Birarda 2016-03-11 11:04:34 -08:00
parent 7ccba8b406
commit 9522c2d17c
4 changed files with 25 additions and 7 deletions

View file

@ -61,13 +61,24 @@ void UploadAssetTask::run() {
if (file.exists()) { if (file.exists()) {
qDebug() << "[WARNING] This file already exists: " << hexHash; qDebug() << "[WARNING] This file already exists: " << hexHash;
} else {
file.open(QIODevice::WriteOnly); replyPacket->writePrimitive(AssetServerError::NoError);
file.write(fileData); replyPacket->write(hash);
} else if (file.open(QIODevice::WriteOnly) && file.write(fileData) == qint64(fileSize)) {
file.close(); file.close();
replyPacket->writePrimitive(AssetServerError::NoError);
replyPacket->write(hash);
} else {
// upload has failed - remove the file and return an error
auto removed = file.remove();
if (!removed) {
qWarning() << "Removal of failed upload file" << hash << "failed.";
}
replyPacket->writePrimitive(AssetServerError::FileOperationFailed);
} }
replyPacket->writePrimitive(AssetServerError::NoError);
replyPacket->write(hash);
} }
auto nodeList = DependencyManager::get<NodeList>(); auto nodeList = DependencyManager::get<NodeList>();

View file

@ -42,6 +42,8 @@ QString AssetUpload::getErrorString() const {
return "The file could not be opened. Please check your permissions and try again."; return "The file could not be opened. Please check your permissions and try again.";
case AssetUpload::NetworkError: case AssetUpload::NetworkError:
return "There was a problem reaching your Asset Server. Please check your network connectivity."; return "There was a problem reaching your Asset Server. Please check your network connectivity.";
case AssetUpload::ServerFileError:
return "The Asset Server failed to store the asset. Please try again.";
default: default:
// not handled, do not show a message box // not handled, do not show a message box
return QString(); return QString();
@ -90,6 +92,9 @@ void AssetUpload::start() {
case AssetServerError::PermissionDenied: case AssetServerError::PermissionDenied:
_error = PermissionDenied; _error = PermissionDenied;
break; break;
case AssetServerError::FileOperationFailed:
_error = ServerFileError;
break;
default: default:
_error = FileOpenError; _error = FileOpenError;
break; break;

View file

@ -32,7 +32,8 @@ public:
Timeout, Timeout,
TooLarge, TooLarge,
PermissionDenied, PermissionDenied,
FileOpenError FileOpenError,
ServerFileError
}; };
static const QString PERMISSION_DENIED_ERROR; static const QString PERMISSION_DENIED_ERROR;

View file

@ -40,7 +40,8 @@ enum AssetServerError : uint8_t {
InvalidByteRange, InvalidByteRange,
AssetTooLarge, AssetTooLarge,
PermissionDenied, PermissionDenied,
MappingOperationFailed MappingOperationFailed,
FileOperationFailed
}; };
enum AssetMappingOperationType : uint8_t { enum AssetMappingOperationType : uint8_t {