Merge pull request #106 from birarda/atp-mappings

add overwriting of files during upload if hash doesn't match
This commit is contained in:
Clément Brisset 2016-03-11 13:27:07 -08:00
commit ac7cbbd960

View file

@ -59,13 +59,26 @@ void UploadAssetTask::run() {
QFile file { _resourcesDir.filePath(QString(hexHash)) };
bool existingCorrectFile = false;
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;
existingCorrectFile = true;
replyPacket->writePrimitive(AssetServerError::NoError);
replyPacket->write(hash);
} else if (file.open(QIODevice::WriteOnly) && file.write(fileData) == qint64(fileSize)) {
qDebug() << "Wrote file" << hash << "to disk. Upload complete";
} else {
qDebug() << "Overwriting an existing file whose contents did not match the expected hash: " << hexHash;
file.close();
}
}
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);
@ -84,6 +97,9 @@ void UploadAssetTask::run() {
}
}
}
auto nodeList = DependencyManager::get<NodeList>();
nodeList->sendPacket(std::move(replyPacket), *_senderNode);
}