Skip to content

Commit

Permalink
when deciding to create a new folder on server: check permissions
Browse files Browse the repository at this point in the history
sometime we need to create a folder on server because some local files
or folders modifications would be lost without that

in that case instead of locally deleting teh folder, we create it back
on server

when doing that, it is important to check the remote permissions such
that we do not try to create a folder in a read-only folder on server

Signed-off-by: Matthieu Gallien <[email protected]>
  • Loading branch information
mgallien committed Aug 22, 2024
1 parent 14a5dd1 commit f44e227
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
16 changes: 15 additions & 1 deletion src/libsync/discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ ProcessDirectoryJob::ProcessDirectoryJob(DiscoveryPhase *data, PinState basePinS
ProcessDirectoryJob::ProcessDirectoryJob(const PathTuple &path, const SyncFileItemPtr &dirItem, QueryMode queryLocal, QueryMode queryServer, qint64 lastSyncTimestamp, ProcessDirectoryJob *parent)
: QObject(parent)
, _dirItem(dirItem)
, _dirParentItem(parent->_dirItem)
, _lastSyncTimestamp(lastSyncTimestamp)
, _queryServer(queryServer)
, _queryLocal(queryLocal)
Expand All @@ -67,9 +68,10 @@ ProcessDirectoryJob::ProcessDirectoryJob(const PathTuple &path, const SyncFileIt
computePinState(parent->_pinState);
}

ProcessDirectoryJob::ProcessDirectoryJob(DiscoveryPhase *data, PinState basePinState, const PathTuple &path, const SyncFileItemPtr &dirItem, QueryMode queryLocal, qint64 lastSyncTimestamp, QObject *parent)
ProcessDirectoryJob::ProcessDirectoryJob(DiscoveryPhase *data, PinState basePinState, const PathTuple &path, const SyncFileItemPtr &dirItem, const SyncFileItemPtr &parentDirItem, QueryMode queryLocal, qint64 lastSyncTimestamp, QObject *parent)
: QObject(parent)
, _dirItem(dirItem)
, _dirParentItem(parentDirItem)
, _lastSyncTimestamp(lastSyncTimestamp)
, _queryLocal(queryLocal)
, _discoveryData(data)
Expand Down Expand Up @@ -2017,6 +2019,18 @@ int ProcessDirectoryJob::processSubJobs(int nbJobs)
if (_childModified && _dirItem->_instruction == CSYNC_INSTRUCTION_REMOVE) {
// re-create directory that has modified contents
_dirItem->_instruction = CSYNC_INSTRUCTION_NEW;

const auto perms = !_rootPermissions.isNull() ? _rootPermissions
: _dirParentItem ? _dirParentItem->_remotePerm : _rootPermissions;

if (perms.isNull()) {
// No permissions set
} else if (_dirItem->isDirectory() && !perms.hasPermission(RemotePermissions::CanAddSubDirectories)) {
qCWarning(lcDisco) << "checkForPermission: ERROR" << _dirItem->_file;
_dirItem->_instruction = CSYNC_INSTRUCTION_ERROR;
_dirItem->_errorString = tr("Not allowed because you don't have permission to add subfolders to that folder");
}

_dirItem->_direction = _dirItem->_direction == SyncFileItem::Up ? SyncFileItem::Down : SyncFileItem::Up;
}
if (_childModified && _dirItem->_instruction == CSYNC_INSTRUCTION_TYPE_CHANGE && !_dirItem->isDirectory()) {
Expand Down
5 changes: 3 additions & 2 deletions src/libsync/discovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ class ProcessDirectoryJob : public QObject
QueryMode queryLocal, QueryMode queryServer, qint64 lastSyncTimestamp,
ProcessDirectoryJob *parent);

explicit ProcessDirectoryJob(DiscoveryPhase *data, PinState basePinState, const PathTuple &path, const SyncFileItemPtr &dirItem,
QueryMode queryLocal, qint64 lastSyncTimestamp, QObject *parent);
explicit ProcessDirectoryJob(DiscoveryPhase *data, PinState basePinState, const PathTuple &path, const SyncFileItemPtr &dirItem, const SyncFileItemPtr &parentDirItem,
QueryMode queryLocal, qint64 lastSyncTimestamp, QObject *parent);

void start();
/** Start up to nbJobs, return the number of job started; emit finished() when done */
Expand All @@ -126,6 +126,7 @@ class ProcessDirectoryJob : public QObject
}

SyncFileItemPtr _dirItem;
SyncFileItemPtr _dirParentItem;

private:
struct Entries
Expand Down
1 change: 1 addition & 0 deletions src/libsync/syncengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,7 @@ void SyncEngine::startSync()
pinState,
path,
singleItemDiscoveryOptions().discoveryDirItem,
{},
localQueryMode,
_journal->keyValueStoreGetInt("last_sync", 0),
_discoveryPhase.data()
Expand Down

0 comments on commit f44e227

Please sign in to comment.