From e46ab72718cb7be7daf28cb80d3cc8f1b0755133 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Wed, 22 Oct 2014 17:13:34 +0200 Subject: [PATCH] SocketAPI: Show error when we are not allowed Issue #1931 --- src/mirall/socketapi.cpp | 28 +++++++++++++++++++++++++++- src/mirall/socketapi.h | 1 - 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/mirall/socketapi.cpp b/src/mirall/socketapi.cpp index f55809787..d0806e139 100644 --- a/src/mirall/socketapi.cpp +++ b/src/mirall/socketapi.cpp @@ -558,7 +558,11 @@ SyncFileStatus SocketApi::fileStatus(Folder *folder, const QString& systemFileNa if( FileSystem::getModTime(fi.absoluteFilePath()) == Utility::qDateTimeToTime_t(rec._modtime) ) { status.set(SyncFileStatus::STATUS_SYNC); } else { - status.set(SyncFileStatus::STATUS_EVAL); + if (rec._remotePerm.isNull() || rec._remotePerm.contains("W") ) { + status.set(SyncFileStatus::STATUS_EVAL); + } else { + status.set(SyncFileStatus::STATUS_ERROR); + } } } else { qDebug() << Q_FUNC_INFO << "Could not determine state for file" << fileName << "will set STATUS_NEW"; @@ -577,6 +581,28 @@ SyncFileStatus SocketApi::fileStatus(Folder *folder, const QString& systemFileNa status.setSharedWithMe(true); } } + if (status.tag() == SyncFileStatus::STATUS_NEW) { + // check the parent folder if it is shared and if it is allowed to create a file/dir within + QDir d( fi.path() ); + auto parentPath = d.path(); + auto dirRec = dbFileRecord_capi(folder, parentPath); + bool isDir = type == CSYNC_FTW_TYPE_DIR; + while( !d.isRoot() && !(d.exists() && dirRec.isValid()) ) { + d.cdUp(); // returns true if the dir exists. + + parentPath = d.path(); + // cut the folder path + dirRec = dbFileRecord_capi(folder, parentPath); + + isDir = true; + } + if( dirRec.isValid() && !dirRec._remotePerm.isNull()) { + if( (isDir && !dirRec._remotePerm.contains("K")) + || (!isDir && !dirRec._remotePerm.contains("C")) ) { + status.set(SyncFileStatus::STATUS_ERROR); + } + } + } return status; } diff --git a/src/mirall/socketapi.h b/src/mirall/socketapi.h index 24460bd87..2f3446ee8 100644 --- a/src/mirall/socketapi.h +++ b/src/mirall/socketapi.h @@ -65,7 +65,6 @@ private slots: private: SyncFileStatus fileStatus(Folder *folder, const QString& systemFileName, c_strlist_t *excludes ); - SyncJournalFileRecord dbFileRecord( Folder *folder, QString fileName ); SyncJournalFileRecord dbFileRecord_capi( Folder *folder, QString fileName ); SyncFileStatus recursiveFolderStatus(Folder *folder, const QString& fileName, c_strlist_t *excludes ); SqlQuery *getSqlQuery( Folder *folder );