Skip to content

Commit

Permalink
Iteration.
Browse files Browse the repository at this point in the history
Signed-off-by: alex-z <[email protected]>
  • Loading branch information
allexzander committed Feb 24, 2024
1 parent 1438e72 commit 3671582
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 8 deletions.
21 changes: 17 additions & 4 deletions src/common/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -693,15 +693,28 @@ QString Utility::noLeadingSlashPath(const QString &path)
return path.startsWith(slash) ? path.mid(1) : path;
}

QString Utility::noTrailingSlashPath(const QString &path)
{
static const auto slash = QLatin1Char('/');
return path.endsWith(slash) ? path.chopped(1) : path;
}

QString Utility::fullRemotePathToRemoteSyncRootRelative(const QString &fullRemotePath, const QString &remoteSyncRoot)
{
const auto remoteSyncRootNoLeadingSlashWithTrailingSlash = Utility::trailingSlashPath(noLeadingSlashPath(remoteSyncRoot));
const auto fullRemotePathNoLeadingSlash = noLeadingSlashPath(fullRemotePath);
const auto relativePathToRemoteSyncRoot = remoteSyncRootNoLeadingSlashWithTrailingSlash != QStringLiteral("/") && fullRemotePathNoLeadingSlash.startsWith(remoteSyncRootNoLeadingSlashWithTrailingSlash)
? fullRemotePathNoLeadingSlash.mid(remoteSyncRootNoLeadingSlashWithTrailingSlash.size())
: fullRemotePath;

if (remoteSyncRootNoLeadingSlashWithTrailingSlash == QStringLiteral("/")) {
return noLeadingSlashPath(noTrailingSlashPath(fullRemotePath));
}

if (!fullRemotePathNoLeadingSlash.startsWith(remoteSyncRootNoLeadingSlashWithTrailingSlash)) {
return fullRemotePath;
}

const auto relativePathToRemoteSyncRoot = fullRemotePathNoLeadingSlash.mid(remoteSyncRootNoLeadingSlashWithTrailingSlash.size());
Q_ASSERT(!relativePathToRemoteSyncRoot.isEmpty());
return noLeadingSlashPath(relativePathToRemoteSyncRoot);
return noLeadingSlashPath(noTrailingSlashPath(relativePathToRemoteSyncRoot));
}


Expand Down
1 change: 1 addition & 0 deletions src/common/utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ namespace Utility {

OCSYNC_EXPORT QString trailingSlashPath(const QString &path);
OCSYNC_EXPORT QString noLeadingSlashPath(const QString &path);
OCSYNC_EXPORT QString noTrailingSlashPath(const QString &path);
OCSYNC_EXPORT QString fullRemotePathToRemoteSyncRootRelative(const QString &fullRemotePath, const QString &remoteSyncRoot);

#ifdef Q_OS_WIN
Expand Down
3 changes: 2 additions & 1 deletion src/libsync/propagatedownloadencrypted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ PropagateDownloadEncrypted::PropagateDownloadEncrypted(OwncloudPropagator *propa
void PropagateDownloadEncrypted::start()
{
SyncJournalFileRecord rec;
if (!_propagator->_journal->getRootE2eFolderRecord(Utility::fullRemotePathToRemoteSyncRootRelative(_remoteParentPath, _propagator->remotePath()), &rec) || !rec.isValid()) {
if (!_propagator->_journal->getRootE2eFolderRecord(Utility::fullRemotePathToRemoteSyncRootRelative(_remoteParentPath, _propagator->remotePath()), &rec)
|| !rec.isValid()) {
emit failed();
return;
}
Expand Down
9 changes: 8 additions & 1 deletion src/libsync/propagateremotemkdir.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,14 @@ void PropagateRemoteMkdir::finalizeMkColJob(QNetworkReply::NetworkError err, con
// We're expecting directory path in /Foo/Bar convention...
Q_ASSERT(jobPath.startsWith('/') && !jobPath.endsWith('/'));
// But encryption job expect it in Foo/Bar/ convention
auto job = new OCC::EncryptFolderJob(propagator()->account(), propagator()->_journal, jobPath.mid(1), _item->_file, propagator()->remotePath(), _item->_fileId, propagator(), _item);
auto job = new OCC::EncryptFolderJob(propagator()->account(),
propagator()->_journal,
jobPath.mid(1),
_item->_file,
propagator()->remotePath(),
_item->_fileId,
propagator(),
_item);
job->setParent(this);
connect(job, &OCC::EncryptFolderJob::finished, this, &PropagateRemoteMkdir::slotEncryptFolderFinished);
job->start();
Expand Down
4 changes: 3 additions & 1 deletion src/libsync/propagateuploadencrypted.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ void PropagateUploadEncrypted::start()
*/
// Encrypt File!
SyncJournalFileRecord rec;
if (!_propagator->_journal->getRootE2eFolderRecord(Utility::fullRemotePathToRemoteSyncRootRelative(_remoteParentAbsolutePath, _propagator->remotePath()), &rec) || !rec.isValid()) {
if (!_propagator->_journal->getRootE2eFolderRecord(Utility::fullRemotePathToRemoteSyncRootRelative(_remoteParentAbsolutePath, _propagator->remotePath()),
&rec)
|| !rec.isValid()) {
emit error();
return;
}
Expand Down
3 changes: 2 additions & 1 deletion src/libsync/updatee2eefoldermetadatajob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ void UpdateE2eeFolderMetadataJob::slotFetchMetadataJobFinished(int httpReturnCod
}

SyncJournalFileRecord rec;
if (!propagator()->_journal->getRootE2eFolderRecord(Utility::fullRemotePathToRemoteSyncRootRelative(_encryptedRemotePath, propagator()->remotePath()), &rec) || !rec.isValid()) {
if (!propagator()->_journal->getRootE2eFolderRecord(Utility::fullRemotePathToRemoteSyncRootRelative(_encryptedRemotePath, propagator()->remotePath()), &rec)
|| !rec.isValid()) {
unlockFolder(EncryptedFolderMetadataHandler::UnlockFolderWithResult::Failure);
return;
}
Expand Down

0 comments on commit 3671582

Please sign in to comment.