mirror of
https://github.com/overte-org/overte.git
synced 2025-04-19 13:43:49 +02:00
add file open and write error handling
This commit is contained in:
parent
7ccba8b406
commit
9522c2d17c
4 changed files with 25 additions and 7 deletions
|
@ -61,13 +61,24 @@ void UploadAssetTask::run() {
|
|||
|
||||
if (file.exists()) {
|
||||
qDebug() << "[WARNING] This file already exists: " << hexHash;
|
||||
} else {
|
||||
file.open(QIODevice::WriteOnly);
|
||||
file.write(fileData);
|
||||
|
||||
replyPacket->writePrimitive(AssetServerError::NoError);
|
||||
replyPacket->write(hash);
|
||||
} else if (file.open(QIODevice::WriteOnly) && file.write(fileData) == qint64(fileSize)) {
|
||||
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>();
|
||||
|
|
|
@ -42,6 +42,8 @@ QString AssetUpload::getErrorString() const {
|
|||
return "The file could not be opened. Please check your permissions and try again.";
|
||||
case AssetUpload::NetworkError:
|
||||
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:
|
||||
// not handled, do not show a message box
|
||||
return QString();
|
||||
|
@ -90,6 +92,9 @@ void AssetUpload::start() {
|
|||
case AssetServerError::PermissionDenied:
|
||||
_error = PermissionDenied;
|
||||
break;
|
||||
case AssetServerError::FileOperationFailed:
|
||||
_error = ServerFileError;
|
||||
break;
|
||||
default:
|
||||
_error = FileOpenError;
|
||||
break;
|
||||
|
|
|
@ -32,7 +32,8 @@ public:
|
|||
Timeout,
|
||||
TooLarge,
|
||||
PermissionDenied,
|
||||
FileOpenError
|
||||
FileOpenError,
|
||||
ServerFileError
|
||||
};
|
||||
|
||||
static const QString PERMISSION_DENIED_ERROR;
|
||||
|
|
|
@ -40,7 +40,8 @@ enum AssetServerError : uint8_t {
|
|||
InvalidByteRange,
|
||||
AssetTooLarge,
|
||||
PermissionDenied,
|
||||
MappingOperationFailed
|
||||
MappingOperationFailed,
|
||||
FileOperationFailed
|
||||
};
|
||||
|
||||
enum AssetMappingOperationType : uint8_t {
|
||||
|
|
Loading…
Reference in a new issue