Skip to content

Commit d3a874f

Browse files
committed
fix(vfs/windows): fix creation of items inside virtual folders
Signed-off-by: Matthieu Gallien <[email protected]>
1 parent d0126ef commit d3a874f

File tree

3 files changed

+53
-10
lines changed

3 files changed

+53
-10
lines changed

src/libsync/account.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1219,9 +1219,19 @@ void Account::listRemoteFolder(QPromise<OCC::PlaceholderCreateInfo> *promise, co
12191219
promise->finish();
12201220
});
12211221

1222-
QObject::connect(listFolderJob, &OCC::LsColJob::directoryListingIterated, this, [promise, path] (const QString &name, const QMap<QString, QString> &properties) {
1222+
auto ignoreFirst = true;
1223+
QObject::connect(listFolderJob, &OCC::LsColJob::directoryListingIterated, this, [&ignoreFirst, promise, path] (const QString &name, const QMap<QString, QString> &properties) {
1224+
if (ignoreFirst) {
1225+
ignoreFirst = false;
1226+
return;
1227+
}
1228+
12231229
qCInfo(lcAccount()) << "ls col job" << path << "new file" << name << properties.count();
1224-
promise->emplaceResult(name, name.toStdWString(), properties);
1230+
1231+
const auto slash = name.lastIndexOf('/');
1232+
const auto realEntryName = name.mid(slash + 1);
1233+
1234+
promise->emplaceResult(realEntryName, realEntryName.toStdWString(), properties);
12251235
});
12261236

12271237
promise->start();

src/libsync/vfs/cfapi/cfapiwrapper.cpp

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,8 @@ void cfApiSendPlaceholdersTransferInfo(const CF_CONNECTION_KEY &connectionKey,
136136
NTSTATUS status,
137137
const QList<OCC::PlaceholderCreateInfo> &newEntries,
138138
qint64 currentPlaceholdersCount,
139-
qint64 totalPlaceholdersCount)
139+
qint64 totalPlaceholdersCount,
140+
const QString &serverPath)
140141
{
141142
CF_OPERATION_INFO opInfo = { 0 };
142143
CF_OPERATION_PARAMETERS opParams = { 0 };
@@ -147,6 +148,7 @@ void cfApiSendPlaceholdersTransferInfo(const CF_CONNECTION_KEY &connectionKey,
147148
const auto &entryInfo = newEntries[i];
148149
auto &newPlaceholder = newPlaceholders[i];
149150

151+
const auto entryFileName = entryInfo.name.mid(serverPath.length());
150152
const auto &fileId = entryInfo.properties[QStringLiteral("fileid")];
151153
const auto fileSize = entryInfo.properties[QStringLiteral("size")].toULongLong();
152154
auto fileMtimeString = entryInfo.properties[QStringLiteral("getlastmodified")];
@@ -156,7 +158,7 @@ void cfApiSendPlaceholdersTransferInfo(const CF_CONNECTION_KEY &connectionKey,
156158
const auto &fileResourceType = entryInfo.properties[QStringLiteral("resourcetype")];
157159
const auto isDir = QStringLiteral("<collection></collection>") == fileResourceType;
158160

159-
qCInfo(lcCfApiWrapper()) << entryInfo.name
161+
qCInfo(lcCfApiWrapper()) << entryFileName
160162
<< "fileId:" << fileId
161163
<< "fileSize:" << fileSize
162164
<< "fileMtime:" << fileMtime
@@ -523,16 +525,18 @@ void CALLBACK cfApiFetchPlaceHolders(const CF_CALLBACK_INFO *callbackInfo, const
523525
STATUS_UNSUCCESSFUL,
524526
{},
525527
0,
526-
0);
528+
0,
529+
{});
527530
};
528531

529-
const auto sendTransferInfo = [=](const QList<OCC::PlaceholderCreateInfo> &newEntries) {
532+
const auto sendTransferInfo = [=](const QList<OCC::PlaceholderCreateInfo> &newEntries, const QString &serverPath) {
530533
cfApiSendPlaceholdersTransferInfo(callbackInfo->ConnectionKey,
531534
callbackInfo->TransferKey,
532535
STATUS_SUCCESS,
533536
newEntries,
534537
newEntries.size(),
535-
newEntries.size());
538+
newEntries.size(),
539+
serverPath);
536540
};
537541

538542
auto vfs = reinterpret_cast<OCC::VfsCfApi *>(callbackInfo->CallbackContext);
@@ -593,21 +597,23 @@ void CALLBACK cfApiFetchPlaceHolders(const CF_CALLBACK_INFO *callbackInfo, const
593597

594598
qCInfo(lcCfApiWrapper()) << "ls prop finished" << path << serverPath << "discovered new entries:" << newEntries.size();
595599

596-
sendTransferInfo(newEntries);
600+
sendTransferInfo(newEntries, serverPath);
597601

598602
auto newPlaceholdersResult = 0;
599603
const auto invokeFinalizeResult = QMetaObject::invokeMethod(vfs,
600-
[&newPlaceholdersResult, vfs, &newEntries, &serverPath] { return vfs->finalizeNewPlaceholders(newEntries, serverPath); },
604+
[&newPlaceholdersResult, vfs, &newEntries, &serverPath] () -> int { return vfs->finalizeNewPlaceholders(newEntries, serverPath); },
601605
Qt::BlockingQueuedConnection,
602-
&newPlaceholdersResult);
606+
qReturnArg(newPlaceholdersResult));
603607
if (!invokeFinalizeResult) {
604608
qCritical(lcCfApiWrapper) << "Failed to finalize hydration job for" << path << requestId;
605609
sendTransferError();
606610
}
611+
qCInfo(lcCfApiWrapper) << "call for finalizeNewPlaceholders was done";
607612

608613
if (!newPlaceholdersResult) {
609614
sendTransferError();
610615
}
616+
qCInfo(lcCfApiWrapper) << "call for finalizeNewPlaceholders succeeded";
611617
}
612618

613619
void CALLBACK cfApiNotifyFileCloseCompletion(const CF_CALLBACK_INFO *callbackInfo, const CF_CALLBACK_PARAMETERS * /*callbackParameters*/)

src/libsync/vfs/cfapi/vfs_cfapi.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -534,6 +534,31 @@ int VfsCfApi::finalizeNewPlaceholders(const QList<PlaceholderCreateInfo> &newEnt
534534
{
535535
const auto &journal = params().journal;
536536

537+
for (const auto &entryInfo : newEntries) {
538+
const auto &fileEtag = entryInfo.properties[QStringLiteral("getetag")];
539+
const auto &fileId = entryInfo.properties[QStringLiteral("fileid")];
540+
const auto fileSize = entryInfo.properties[QStringLiteral("size")].toULongLong();
541+
auto fileMtimeString = entryInfo.properties[QStringLiteral("getlastmodified")];
542+
fileMtimeString.replace("GMT", "+0000");
543+
const auto fileMtime = QDateTime::fromString(fileMtimeString, Qt::RFC2822Date).currentSecsSinceEpoch();
544+
545+
const auto &fileResourceType = entryInfo.properties[QStringLiteral("resourcetype")];
546+
const auto isDir = QStringLiteral("<collection></collection>") == fileResourceType;
547+
548+
auto folderRecord = SyncJournalFileRecord{};
549+
folderRecord._fileId = fileId.toUtf8();
550+
folderRecord._fileSize = fileSize;
551+
folderRecord._etag = fileEtag.toUtf8();
552+
folderRecord._path = entryInfo.name.toUtf8();
553+
folderRecord._type = (isDir ? ItemTypeVirtualDirectory : ItemTypeVirtualFile);
554+
555+
const auto updateRecordDbResult = journal->setFileRecord(folderRecord);
556+
if (!updateRecordDbResult) {
557+
qCWarning(lcCfApi) << "failed: failed to update db record for" << pathString;
558+
return 0;
559+
}
560+
}
561+
537562
auto folderRecord = SyncJournalFileRecord{};
538563
const auto fetchRecordDbResult = journal->getFileRecord(pathString, &folderRecord);
539564
if (!fetchRecordDbResult || !folderRecord.isValid()) {
@@ -548,6 +573,8 @@ int VfsCfApi::finalizeNewPlaceholders(const QList<PlaceholderCreateInfo> &newEnt
548573
return 0;
549574
}
550575

576+
qCInfo(lcCfApi) << "update folder on-demand DB record succeeded";
577+
551578
return 1;
552579
}
553580

0 commit comments

Comments
 (0)