From 57359968ede25738d4138787102ef759b8ca2dfe Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Fri, 23 May 2014 18:54:35 +0200 Subject: [PATCH] Added method localFileNameClash Also reordered the implementations a bit. --- src/mirall/owncloudpropagator.cpp | 59 ++++++++++++++++++++++++------- src/mirall/owncloudpropagator.h | 1 + src/mirall/propagatorjobs.h | 2 +- 3 files changed, 48 insertions(+), 14 deletions(-) diff --git a/src/mirall/owncloudpropagator.cpp b/src/mirall/owncloudpropagator.cpp index edb96778e1..3bcf042668 100644 --- a/src/mirall/owncloudpropagator.cpp +++ b/src/mirall/owncloudpropagator.cpp @@ -21,6 +21,11 @@ #include "propagator_legacy.h" #include "mirall/utility.h" +#ifdef Q_OS_WIN +#include +#include +#endif + #include namespace Mirall { @@ -153,6 +158,8 @@ void PropagateItemJob::slotRestoreJobCompleted(const SyncFileItem& item ) } } +// ================================================================================ + PropagateItemJob* OwncloudPropagator::createJob(const SyncFileItem& item) { switch(item._instruction) { case CSYNC_INSTRUCTION_REMOVE: @@ -281,6 +288,45 @@ bool OwncloudPropagator::useLegacyJobs() return env=="true" || env =="1"; } +int OwncloudPropagator::httpTimeout() +{ + static int timeout; + if (!timeout) { + timeout = qgetenv("OWNCLOUD_TIMEOUT").toUInt(); + if (timeout == 0) { + timeout = 300; // default to 300 secs + } + } + return timeout; +} + +bool OwncloudPropagator::localFileNameClash( const QString& relFile ) +{ + bool re = false; + const QString file( _localDir + relFile ); + qDebug() << "CaseClashCheck for " << file; +#ifdef Q_OS_WIN + WIN32_FIND_DATA FindFileData; + HANDLE hFind; + + hFind = FindFirstFileW( (wchar_t*)file.utf16(), &FindFileData); + if (hFind == INVALID_HANDLE_VALUE) { + qDebug() << "FindFirstFile failed " << GetLastError(); + // returns false. + } else { + QString realFileName = QString::fromWCharArray( FindFileData.cFileName ); + qDebug() << Q_FUNC_INFO << "Real file name is " << realFileName; + FindClose(hFind); + + if( ! file.endsWith(realFileName, Qt::CaseSensitive) ) { + re = true; + } + } +#endif + return re; +} + +// ================================================================================ void PropagateDirectory::start() { @@ -339,17 +385,4 @@ void PropagateDirectory::slotSubJobReady() } } -int OwncloudPropagator::httpTimeout() -{ - static int timeout; - if (!timeout) { - timeout = qgetenv("OWNCLOUD_TIMEOUT").toUInt(); - if (timeout == 0) { - timeout = 300; // default to 300 secs - } - } - return timeout; -} - - } diff --git a/src/mirall/owncloudpropagator.h b/src/mirall/owncloudpropagator.h index cda037f82b..bc95f429c3 100644 --- a/src/mirall/owncloudpropagator.h +++ b/src/mirall/owncloudpropagator.h @@ -211,6 +211,7 @@ public: int _activeJobs; bool isInSharedDirectory(const QString& file); + bool localFileNameClash(const QString& relfile); void abort() { _abortRequested.fetchAndStoreOrdered(true); diff --git a/src/mirall/propagatorjobs.h b/src/mirall/propagatorjobs.h index c256c05556..8a47f2a52c 100644 --- a/src/mirall/propagatorjobs.h +++ b/src/mirall/propagatorjobs.h @@ -81,7 +81,7 @@ class PropagateLocalMkdir : public PropagateItemJob { public: PropagateLocalMkdir (OwncloudPropagator* propagator,const SyncFileItem& item) : PropagateItemJob(propagator, item) {} void start(); - bool hasCaseClash( const QString& file ); + }; class PropagateRemoteRemove : public PropagateNeonJob { Q_OBJECT