|
9 | 9 | #include "accountfwd.h" |
10 | 10 | #include "capabilities.h" |
11 | 11 | #include "clientsideencryptionjobs.h" |
| 12 | +#include "common/utility.h" |
12 | 13 | #include "configfile.h" |
13 | 14 | #include "cookiejar.h" |
14 | 15 | #include "creds/abstractcredentials.h" |
@@ -1174,61 +1175,64 @@ void Account::setAskUserForMnemonic(const bool ask) |
1174 | 1175 | emit askUserForMnemonicChanged(); |
1175 | 1176 | } |
1176 | 1177 |
|
1177 | | -void Account::listRemoteFolder(QPromise<OCC::PlaceholderCreateInfo> *promise, const QString &path, SyncJournalDb *journalForFolder) |
| 1178 | +void Account::listRemoteFolder(QPromise<OCC::PlaceholderCreateInfo> *promise, const QString &remoteSyncRootPath, const QString &subPath, SyncJournalDb *journalForFolder) |
1178 | 1179 | { |
1179 | | - qCInfo(lcAccount()) << "ls col job requested for" << path; |
| 1180 | + qCInfo(lcAccount()) << "ls col job requested for" << subPath; |
1180 | 1181 |
|
1181 | 1182 | if (!credentials()->ready()) { |
1182 | | - qCWarning(lcAccount()) << "credentials are not ready" << path; |
| 1183 | + qCWarning(lcAccount()) << "credentials are not ready" << subPath; |
1183 | 1184 | promise->finish(); |
1184 | 1185 | return; |
1185 | 1186 | } |
1186 | 1187 |
|
1187 | | - auto listFolderJob = new OCC::LsColJob{sharedFromThis(), path}; |
| 1188 | + auto listFolderJob = new OCC::LsColJob{sharedFromThis(), subPath}; |
1188 | 1189 |
|
1189 | 1190 | const auto props = LsColJob::defaultProperties(LsColJob::FolderType::ChildFolder, sharedFromThis()); |
1190 | 1191 |
|
1191 | 1192 | listFolderJob->setProperties(props); |
1192 | 1193 |
|
1193 | | - QObject::connect(listFolderJob, &OCC::LsColJob::networkError, this, [promise, path] (QNetworkReply *reply) { |
| 1194 | + QObject::connect(listFolderJob, &OCC::LsColJob::networkError, this, [promise, subPath] (QNetworkReply *reply) { |
1194 | 1195 | if (reply) { |
1195 | | - qCWarning(lcAccount()) << "ls col job" << path << "error" << reply->errorString(); |
| 1196 | + qCWarning(lcAccount()) << "ls col job" << subPath << "error" << reply->errorString(); |
1196 | 1197 | } |
1197 | 1198 |
|
1198 | | - qCWarning(lcAccount()) << "ls col job" << path << "error without a reply"; |
| 1199 | + qCWarning(lcAccount()) << "ls col job" << subPath << "error without a reply"; |
1199 | 1200 | promise->finish(); |
1200 | 1201 | }); |
1201 | 1202 |
|
1202 | | - QObject::connect(listFolderJob, &OCC::LsColJob::finishedWithError, this, [promise, path] (QNetworkReply *reply) { |
| 1203 | + QObject::connect(listFolderJob, &OCC::LsColJob::finishedWithError, this, [promise, subPath] (QNetworkReply *reply) { |
1203 | 1204 | if (reply) { |
1204 | | - qCWarning(lcAccount()) << "ls col job" << path << "error" << reply->errorString(); |
| 1205 | + qCWarning(lcAccount()) << "ls col job" << subPath << "error" << reply->errorString(); |
1205 | 1206 | } |
1206 | 1207 |
|
1207 | | - qCWarning(lcAccount()) << "ls col job" << path << "error without a reply"; |
| 1208 | + qCWarning(lcAccount()) << "ls col job" << subPath << "error without a reply"; |
1208 | 1209 | promise->finish(); |
1209 | 1210 | }); |
1210 | 1211 |
|
1211 | | - QObject::connect(listFolderJob, &OCC::LsColJob::finishedWithoutError, this, [promise, path] () { |
1212 | | - qCInfo(lcAccount()) << "ls col job" << path << "finished"; |
| 1212 | + QObject::connect(listFolderJob, &OCC::LsColJob::finishedWithoutError, this, [promise, subPath] () { |
| 1213 | + qCInfo(lcAccount()) << "ls col job" << subPath << "finished"; |
1213 | 1214 | promise->finish(); |
1214 | 1215 | }); |
1215 | 1216 |
|
1216 | | - QObject::connect(listFolderJob, &OCC::LsColJob::directoryListingIterated, this, [promise, path, journalForFolder, this](const QString &name, const QMap<QString, QString> &properties) { |
1217 | | - // `name` is e.g. "/remote.php/dav/files/admin" or "/remote.php/dav/files/admin/SomeFolder"; whereas `path` is e.g. "" or "SomeFolder/" |
1218 | | - // in case these two are equal we are currently iterating the entry for the current directory |
1219 | | - const auto serverPath = name.mid(this->davPath().size()); |
1220 | | - const auto isRootCollection = serverPath.isEmpty() && path.isEmpty(); |
1221 | | - const auto isCurrentCollection = isRootCollection || serverPath == Utility::noTrailingSlashPath(path); |
1222 | | - if (isCurrentCollection) { |
| 1217 | + listFolderJob->setProperty("ignoredFirst", false); |
| 1218 | + const auto baseRemotePath = Utility::trailingSlashPath(Utility::noLeadingSlashPath(remoteSyncRootPath)); |
| 1219 | + auto syncRootPath = subPath; |
| 1220 | + if (subPath.startsWith(baseRemotePath)) { |
| 1221 | + syncRootPath = syncRootPath.mid(baseRemotePath.size()); |
| 1222 | + } |
| 1223 | + |
| 1224 | + QObject::connect(listFolderJob, &OCC::LsColJob::directoryListingIterated, this, [promise, remoteSyncRootPath, syncRootPath, journalForFolder, this](const QString &completeDavPath, const QMap<QString, QString> &properties) { |
| 1225 | + if (!sender()->property("ignoredFirst").toBool()) { |
1223 | 1226 | qCDebug(lcAccount()) << "skip first item"; |
| 1227 | + sender()->setProperty("ignoredFirst", true); |
1224 | 1228 | return; |
1225 | 1229 | } |
1226 | 1230 |
|
1227 | | - qCInfo(lcAccount()) << "ls col job" << path << "new file" << name << properties.count(); |
| 1231 | + qCInfo(lcAccount()) << "ls col job" << syncRootPath << "new file" << completeDavPath << properties.count(); |
1228 | 1232 |
|
1229 | | - const auto slash = name.lastIndexOf('/'); |
1230 | | - const auto itemFileName = name.mid(slash + 1); |
1231 | | - const auto absoluteItemPathName = (path.isEmpty() ? itemFileName : path + "/" + itemFileName); |
| 1233 | + const auto slash = completeDavPath.lastIndexOf('/'); |
| 1234 | + const auto itemFileName = completeDavPath.mid(slash + 1); |
| 1235 | + const auto absoluteItemPathName = syncRootPath.isEmpty() ? itemFileName : Utility::noTrailingSlashPath(syncRootPath) + '/' + itemFileName; |
1232 | 1236 |
|
1233 | 1237 | auto currentItemDbRecord = SyncJournalFileRecord{}; |
1234 | 1238 | if (journalForFolder->getFileRecord(absoluteItemPathName, ¤tItemDbRecord) && currentItemDbRecord.isValid()) { |
|
0 commit comments