mirror of
https://github.com/overte-org/overte.git
synced 2025-04-25 22:36:39 +02:00
Merge pull request #106 from birarda/atp-mappings
add overwriting of files during upload if hash doesn't match
This commit is contained in:
commit
ac7cbbd960
1 changed files with 34 additions and 18 deletions
|
@ -59,29 +59,45 @@ void UploadAssetTask::run() {
|
||||||
|
|
||||||
QFile file { _resourcesDir.filePath(QString(hexHash)) };
|
QFile file { _resourcesDir.filePath(QString(hexHash)) };
|
||||||
|
|
||||||
|
bool existingCorrectFile = false;
|
||||||
|
|
||||||
if (file.exists()) {
|
if (file.exists()) {
|
||||||
qDebug() << "[WARNING] This file already exists: " << hexHash;
|
// check if the local file has the correct contents, otherwise we overwrite
|
||||||
|
if (file.open(QIODevice::ReadOnly) && hashData(file.readAll()) == hash) {
|
||||||
|
qDebug() << "Not overwriting existing verified file: " << hexHash;
|
||||||
|
|
||||||
replyPacket->writePrimitive(AssetServerError::NoError);
|
existingCorrectFile = true;
|
||||||
replyPacket->write(hash);
|
|
||||||
} else if (file.open(QIODevice::WriteOnly) && file.write(fileData) == qint64(fileSize)) {
|
|
||||||
qDebug() << "Wrote file" << hash << "to disk. Upload complete";
|
|
||||||
file.close();
|
|
||||||
|
|
||||||
replyPacket->writePrimitive(AssetServerError::NoError);
|
replyPacket->writePrimitive(AssetServerError::NoError);
|
||||||
replyPacket->write(hash);
|
replyPacket->write(hash);
|
||||||
} else {
|
} else {
|
||||||
qWarning() << "Failed to upload or write to file" << hexHash << " - upload failed.";
|
qDebug() << "Overwriting an existing file whose contents did not match the expected hash: " << hexHash;
|
||||||
|
file.close();
|
||||||
// upload has failed - remove the file and return an error
|
|
||||||
auto removed = file.remove();
|
|
||||||
|
|
||||||
if (!removed) {
|
|
||||||
qWarning() << "Removal of failed upload file" << hexHash << "failed.";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
replyPacket->writePrimitive(AssetServerError::FileOperationFailed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!existingCorrectFile) {
|
||||||
|
if (file.open(QIODevice::WriteOnly) && file.write(fileData) == qint64(fileSize)) {
|
||||||
|
qDebug() << "Wrote file" << hexHash << "to disk. Upload complete";
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
replyPacket->writePrimitive(AssetServerError::NoError);
|
||||||
|
replyPacket->write(hash);
|
||||||
|
} else {
|
||||||
|
qWarning() << "Failed to upload or write to file" << hexHash << " - upload failed.";
|
||||||
|
|
||||||
|
// upload has failed - remove the file and return an error
|
||||||
|
auto removed = file.remove();
|
||||||
|
|
||||||
|
if (!removed) {
|
||||||
|
qWarning() << "Removal of failed upload file" << hexHash << "failed.";
|
||||||
|
}
|
||||||
|
|
||||||
|
replyPacket->writePrimitive(AssetServerError::FileOperationFailed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
auto nodeList = DependencyManager::get<NodeList>();
|
auto nodeList = DependencyManager::get<NodeList>();
|
||||||
|
|
Loading…
Reference in a new issue