UploadDevice: Fix windows issues #7264

- Close the UploadDevice to close the QFile after the PUT job is done.
  This allows winvfs to get an oplock on the file later.

- Don't rely on QFile::fileName() to be valid after
  openAndSeekFileSharedRead() was called. The way it is openend on
  Windows makes it have an empty filename.
This commit is contained in:
Christian Kamm 2019-06-21 11:34:59 +02:00
parent 02a9b16b0f
commit b99c08904e
2 changed files with 19 additions and 11 deletions

View File

@ -91,6 +91,19 @@ void PUTFileJob::start()
AbstractNetworkJob::start();
}
bool PUTFileJob::finished()
{
_device->close();
qCInfo(lcPutJob) << "PUT of" << reply()->request().url().toString() << "FINISHED WITH STATUS"
<< replyStatusString()
<< reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute)
<< reply()->attribute(QNetworkRequest::HttpReasonPhraseAttribute);
emit finishedSignal();
return true;
}
void PollJob::start()
{
setTimeout(120 * 1000);
@ -343,13 +356,17 @@ bool UploadDevice::open(QIODevice::OpenMode mode)
if (mode & QIODevice::WriteOnly)
return false;
// Get the file size now: _file.fileName() is no longer reliable
// on all platforms after openAndSeekFileSharedRead().
auto fileDiskSize = FileSystem::getSize(_file.fileName());
QString openError;
if (!FileSystem::openAndSeekFileSharedRead(&_file, &openError, _start)) {
setErrorString(openError);
return false;
}
_size = qBound(0ll, _size, FileSystem::getSize(_file.fileName()) - _start);
_size = qBound(0ll, _size, fileDiskSize - _start);
_read = 0;
return QIODevice::open(mode);

View File

@ -121,16 +121,7 @@ public:
virtual void start() Q_DECL_OVERRIDE;
virtual bool finished() Q_DECL_OVERRIDE
{
qCInfo(lcPutJob) << "PUT of" << reply()->request().url().toString() << "FINISHED WITH STATUS"
<< replyStatusString()
<< reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute)
<< reply()->attribute(QNetworkRequest::HttpReasonPhraseAttribute);
emit finishedSignal();
return true;
}
virtual bool finished() Q_DECL_OVERRIDE;
QIODevice *device()
{