Merge pull request #3260 from nextcloud/fix/cherryPickFixes

Fix/cherry pick fixes
This commit is contained in:
Matthieu Gallien 2021-05-06 09:55:04 +02:00 committed by GitHub
commit 8f7646d93f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 34 additions and 29 deletions

View file

@ -72,7 +72,7 @@ IFACEMETHODIMP_(ULONG) NCContextMenu::Release()
// Initialize the context menu handler.
IFACEMETHODIMP NCContextMenu::Initialize(
LPCITEMIDLIST pidlFolder, LPDATAOBJECT pDataObj, HKEY hKeyProgID)
LPCITEMIDLIST, LPDATAOBJECT pDataObj, HKEY)
{
m_selectedFiles.clear();

View file

@ -141,7 +141,7 @@ bool FileSystem::rename(const QString &originFileName,
(wchar_t *)dest.utf16(),
MOVEFILE_COPY_ALLOWED | MOVEFILE_WRITE_THROUGH);
if (!success) {
error = Utility::formatLastWinError();
error = Utility::formatWinError(GetLastError());
}
} else
#endif

View file

@ -275,20 +275,19 @@ int SqlQuery::prepare(const QByteArray &sql, bool allow_failure)
* There is no overloads to QByteArray::startWith that takes Qt::CaseInsensitive.
* Returns true if 'a' starts with 'b' in a case insensitive way
*/
static bool startsWithInsensitive(const QByteArray &a, const char *b)
static bool startsWithInsensitive(const QByteArray &a, const QByteArray &b)
{
size_t len = strlen(b);
return a.size() >= len && qstrnicmp(a.constData(), b, Utility::convertSizeToUint(len)) == 0;
return a.size() >= b.size() && qstrnicmp(a.constData(), b.constData(), static_cast<uint>(b.size())) == 0;
}
bool SqlQuery::isSelect()
{
return startsWithInsensitive(_sql, "SELECT");
return startsWithInsensitive(_sql, QByteArrayLiteral("SELECT"));
}
bool SqlQuery::isPragma()
{
return startsWithInsensitive(_sql, "PRAGMA");
return startsWithInsensitive(_sql, QByteArrayLiteral("PRAGMA"));
}
bool SqlQuery::exec()

View file

@ -250,9 +250,6 @@ namespace Utility {
OCSYNC_EXPORT void UnixTimeToLargeIntegerFiletime(time_t t, LARGE_INTEGER *hundredNSecs);
OCSYNC_EXPORT QString formatWinError(long error);
inline QString formatLastWinError() {
return formatWinError(GetLastError());
};
class OCSYNC_EXPORT NtfsPermissionLookupRAII
{

View file

@ -73,7 +73,7 @@ OCSYNC_EXPORT void csync_exclude_expand_escapes(QByteArray &input)
line[o++] = line[i];
}
}
input.resize(OCC::Utility::convertSizeToUint(o));
input.resize(OCC::Utility::convertSizeToInt(o));
}
// See http://support.microsoft.com/kb/74496 and
@ -139,7 +139,7 @@ static CSYNC_EXCLUDE_TYPE _csync_excluded_common(const QString &path, bool exclu
bname = path.midRef(lastSlash + 1);
}
size_t blen = bname.size();
qsizetype blen = bname.size();
// 9 = strlen(".sync_.db")
if (blen >= 9 && bname.at(0) == QLatin1Char('.')) {
if (bname.contains(QLatin1String(".db"))) {

View file

@ -45,7 +45,8 @@ void WatcherThread::watchChanges(size_t fileNotifyBufferSize,
nullptr);
if (_directory == INVALID_HANDLE_VALUE) {
qCWarning(lcFolderWatcher) << "Failed to create handle for" << _path << ", error:" << Utility::formatLastWinError();
const auto error = GetLastError();
qCWarning(lcFolderWatcher) << "Failed to create handle for" << _path << ", error:" << Utility::formatWinError(error);
_directory = 0;
return;
}
@ -94,12 +95,13 @@ void WatcherThread::watchChanges(size_t fileNotifyBufferSize,
2, handles,
false, // awake once one of them arrives
INFINITE);
const auto error = GetLastError();
if (result == 1) {
qCDebug(lcFolderWatcher) << "Received stop event, aborting folder watcher thread";
break;
}
if (result != 0) {
qCWarning(lcFolderWatcher) << "WaitForMultipleObjects failed" << result << Utility::formatLastWinError();
qCWarning(lcFolderWatcher) << "WaitForMultipleObjects failed" << result << Utility::formatWinError(error);
break;
}
@ -128,10 +130,11 @@ void WatcherThread::watchChanges(size_t fileNotifyBufferSize,
&& curEntry->Action != FILE_ACTION_RENAMED_OLD_NAME) {
const auto wfile = longfile.toStdWString();
const int longNameSize = GetLongPathNameW(wfile.data(), fileNameBuffer, fileNameBufferSize);
const auto error = GetLastError();
if (longNameSize > 0) {
longfile = QString::fromWCharArray(fileNameBuffer, longNameSize);
} else {
qCWarning(lcFolderWatcher) << "Error converting file name" << longfile << "to full length, keeping original name." << Utility::formatLastWinError();
qCWarning(lcFolderWatcher) << "Error converting file name" << longfile << "to full length, keeping original name." << Utility::formatWinError(error);
}
}

View file

@ -49,7 +49,7 @@ AccessManager::AccessManager(QObject *parent)
setCookieJar(new CookieJar);
}
static QByteArray generateRequestId()
QByteArray AccessManager::generateRequestId()
{
// Use a UUID with the starting and ending curly brace removed.
auto uuid = QUuid::createUuid().toByteArray();

View file

@ -32,6 +32,8 @@ class OWNCLOUDSYNC_EXPORT AccessManager : public QNetworkAccessManager
Q_OBJECT
public:
static QByteArray generateRequestId();
AccessManager(QObject *parent = nullptr);
protected:

View file

@ -885,16 +885,15 @@ void ProcessDirectoryJob::processFileAnalyzeLocalInfo(
item->_type = localEntry.isDirectory ? ItemTypeDirectory : localEntry.isVirtualFile ? ItemTypeVirtualFile : ItemTypeFile;
_childModified = true;
auto postProcessLocalNew = [item, localEntry, this]() {
auto postProcessLocalNew = [item, localEntry, path, this]() {
if (localEntry.isVirtualFile) {
// Remove the spurious file if it looks like a placeholder file
// (we know placeholder files contain " ", but only in the suffix case)
if (localEntry.size <= 1 || !isVfsWithSuffix()) {
qCWarning(lcDisco) << "Wiping virtual file without db entry for" << _currentFolder._local + "/" + localEntry.name;
const bool isPlaceHolder = _discoveryData->_syncOptions._vfs->isDehydratedPlaceholder(_discoveryData->_localDir + path._local);
if (isPlaceHolder) {
qCWarning(lcDisco) << "Wiping virtual file without db entry for" << path._local;
item->_instruction = CSYNC_INSTRUCTION_REMOVE;
item->_direction = SyncFileItem::Down;
} else {
qCWarning(lcDisco) << "Virtual file without db entry for" << _currentFolder._local << localEntry.name
qCWarning(lcDisco) << "Virtual file without db entry for" << path._local
<< "but looks odd, keeping";
item->_instruction = CSYNC_INSTRUCTION_IGNORE;
}

View file

@ -6,6 +6,8 @@
*/
#include "syncenginetestutils.h"
#include "httplogger.h"
#include "accessmanager.h"
#include <memory>
@ -803,27 +805,30 @@ QNetworkReply *FakeQNAM::createRequest(QNetworkAccessManager::Operation op, cons
bool isUpload = request.url().path().startsWith(sUploadUrl.path());
FileInfo &info = isUpload ? _uploadFileInfo : _remoteRootFileInfo;
auto newRequest = request;
newRequest.setRawHeader("X-Request-ID", OCC::AccessManager::generateRequestId());
auto verb = request.attribute(QNetworkRequest::CustomVerbAttribute);
FakeReply *reply = nullptr;
if (verb == QLatin1String("PROPFIND"))
// Ignore outgoingData always returning somethign good enough, works for now.
reply = new FakePropfindReply { info, op, request, this };
reply = new FakePropfindReply { info, op, newRequest, this };
else if (verb == QLatin1String("GET") || op == QNetworkAccessManager::GetOperation)
reply = new FakeGetReply { info, op, request, this };
reply = new FakeGetReply { info, op, newRequest, this };
else if (verb == QLatin1String("PUT") || op == QNetworkAccessManager::PutOperation)
reply = new FakePutReply { info, op, request, outgoingData->readAll(), this };
reply = new FakePutReply { info, op, newRequest, outgoingData->readAll(), this };
else if (verb == QLatin1String("MKCOL"))
reply = new FakeMkcolReply { info, op, request, this };
reply = new FakeMkcolReply { info, op, newRequest, this };
else if (verb == QLatin1String("DELETE") || op == QNetworkAccessManager::DeleteOperation)
reply = new FakeDeleteReply { info, op, request, this };
reply = new FakeDeleteReply { info, op, newRequest, this };
else if (verb == QLatin1String("MOVE") && !isUpload)
reply = new FakeMoveReply { info, op, request, this };
reply = new FakeMoveReply { info, op, newRequest, this };
else if (verb == QLatin1String("MOVE") && isUpload)
reply = new FakeChunkMoveReply { info, _remoteRootFileInfo, op, request, this };
reply = new FakeChunkMoveReply { info, _remoteRootFileInfo, op, newRequest, this };
else {
qDebug() << verb << outgoingData;
Q_UNREACHABLE();
}
OCC::HttpLogger::logRequest(reply, op, outgoingData);
return reply;
}