[Pkg-owncloud-commits] [owncloud-client] 137/164: Uploads: Fix big seeks on Windows. #2954
Sandro Knauß
hefee-guest at moszumanska.debian.org
Sun Mar 22 11:57:05 UTC 2015
This is an automated email from the git hooks/post-receive script.
hefee-guest pushed a commit to branch master
in repository owncloud-client.
commit 1dd34889736d67edb952dc0712009ee187ef0739
Author: Christian Kamm <kamm at incasoftware.de>
Date: Thu Mar 12 13:18:08 2015 +0100
Uploads: Fix big seeks on Windows. #2954
---
src/libsync/filesystem.cpp | 47 ++++++++++++++++++++++++++---------------
src/libsync/filesystem.h | 8 +++----
src/libsync/propagateupload.cpp | 8 ++-----
3 files changed, 36 insertions(+), 27 deletions(-)
diff --git a/src/libsync/filesystem.cpp b/src/libsync/filesystem.cpp
index ba94db0..8411d93 100644
--- a/src/libsync/filesystem.cpp
+++ b/src/libsync/filesystem.cpp
@@ -204,12 +204,12 @@ bool FileSystem::renameReplace(const QString& originFileName, const QString& des
return true;
}
-bool FileSystem::openFileSharedRead(QFile* file, QString* error)
+bool FileSystem::openAndSeekFileSharedRead(QFile* file, QString* errorOrNull, qint64 seek)
{
- bool ok = false;
- if (error) {
- error->clear();
- }
+ QString errorDummy;
+ // avoid many if (errorOrNull) later.
+ QString& error = errorOrNull ? *errorOrNull : errorDummy;
+ error.clear();
#ifdef Q_OS_WIN
//
@@ -236,9 +236,7 @@ bool FileSystem::openFileSharedRead(QFile* file, QString* error)
// Bail out on error.
if (fileHandle == INVALID_HANDLE_VALUE) {
- if (error) {
- *error = qt_error_string();
- }
+ error = qt_error_string();
return false;
}
@@ -247,19 +245,34 @@ bool FileSystem::openFileSharedRead(QFile* file, QString* error)
// the fd the handle will be closed too.
int fd = _open_osfhandle((intptr_t)fileHandle, _O_RDONLY);
if (fd == -1) {
- if (error) {
- *error = "could not make fd from handle";
- }
+ error = "could not make fd from handle";
+ return false;
+ }
+ if (!file->open(fd, QIODevice::ReadOnly, QFile::AutoCloseHandle)) {
+ error = file->errorString();
+ return false;
+ }
+
+ // Seek to the right spot
+ LARGE_INTEGER *li = reinterpret_cast<LARGE_INTEGER*>(&seek);
+ DWORD newFilePointer = SetFilePointer(fileHandle, li->LowPart, &li->HighPart, FILE_BEGIN);
+ if (newFilePointer == 0xFFFFFFFF && GetLastError() != NO_ERROR) {
+ error = qt_error_string();
return false;
}
- ok = file->open(fd, QIODevice::ReadOnly, QFile::AutoCloseHandle);
+
+ return true;
#else
- ok = file->open(QFile::ReadOnly);
-#endif
- if (! ok && error) {
- *error = file->errorString();
+ if (!file->open(QFile::ReadOnly)) {
+ error = file->errorString();
+ return false;
}
- return ok;
+ if (!file->seek(seek)) {
+ error = file->errorString();
+ return false;
+ }
+ return true;
+#endif
}
#ifdef Q_OS_WIN
diff --git a/src/libsync/filesystem.h b/src/libsync/filesystem.h
index 845ffc4..eee0721 100644
--- a/src/libsync/filesystem.h
+++ b/src/libsync/filesystem.h
@@ -75,13 +75,13 @@ bool renameReplace(const QString &originFileName, const QString &destinationFile
QString *errorString);
/**
- * Replacement for QFile::open(ReadOnly) that sets a more permissive sharing mode
- * on Windows.
+ * Replacement for QFile::open(ReadOnly) followed by a seek().
+ * This version sets a more permissive sharing mode on Windows.
*
* Warning: The resuting file may have an empty fileName and be unsuitable for use
- * with QFileInfo!
+ * with QFileInfo! Calling seek() on the QFile with >32bit signed values will fail!
*/
-bool openFileSharedRead(QFile* file, QString* error);
+bool openAndSeekFileSharedRead(QFile* file, QString* error, qint64 seek);
#ifdef Q_OS_WIN
/**
diff --git a/src/libsync/propagateupload.cpp b/src/libsync/propagateupload.cpp
index 49b213d..b16507c 100644
--- a/src/libsync/propagateupload.cpp
+++ b/src/libsync/propagateupload.cpp
@@ -232,17 +232,13 @@ bool UploadDevice::prepareAndOpen(const QString& fileName, qint64 start, qint64
QFile file(fileName);
QString openError;
- if (!FileSystem::openFileSharedRead(&file, &openError)) {
+ if (!FileSystem::openAndSeekFileSharedRead(&file, &openError, start)) {
setErrorString(openError);
return false;
}
- size = qMin(FileSystem::getSize(fileName), size);
+ size = qBound(0ll, size, FileSystem::getSize(fileName) - start);
_data.resize(size);
- if (!file.seek(start)) {
- setErrorString(file.errorString());
- return false;
- }
auto read = file.read(_data.data(), size);
if (read != size) {
setErrorString(file.errorString());
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git
More information about the Pkg-owncloud-commits
mailing list