Skip to content

Commit

Permalink
fix: implement FakeFolder::fromDisk using csync functions to bypass Q…
Browse files Browse the repository at this point in the history
…File::encodeName()
  • Loading branch information
DeepDiver1975 committed Jan 24, 2025
1 parent b7dfb85 commit aa3684b
Showing 1 changed file with 20 additions and 15 deletions.
35 changes: 20 additions & 15 deletions test/testutils/syncenginetestutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "libsync/syncresult.h"

#include <thread>
#include <vio/csync_vio_local.h>

using namespace std::chrono_literals;
using namespace std::chrono;
Expand Down Expand Up @@ -1099,34 +1100,38 @@ void FakeFolder::toDisk(QDir &dir, const FileInfo &templateFi)

void FakeFolder::fromDisk(QDir &dir, FileInfo &templateFi)
{
const auto infoList = dir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot);
for (const auto &diskChild : infoList) {
if (diskChild.isHidden() || diskChild.fileName().startsWith(QStringLiteral(".sync_"))) {
// Skip system files, sqlite db files, sync log, etc.
auto dh = csync_vio_local_opendir(dir.absolutePath());
if (!dh) {
return;
}
while (true) {
auto dirent = csync_vio_local_readdir(dh, nullptr);
if (!dirent)
break;
if (dirent->type == ItemTypeSkip)
continue;
}

if (diskChild.isDir()) {
if (dirent->type == ItemTypeDirectory) {
QDir subDir = dir;
subDir.cd(diskChild.fileName());
FileInfo &subFi = templateFi.children[diskChild.fileName()] = FileInfo { diskChild.fileName() };
subFi.setLastModified(diskChild.lastModified());
subDir.cd(dirent->path);
FileInfo &subFi = templateFi.children[dirent->path] = FileInfo{dirent->path};
subFi.setLastModified(QDateTime::fromSecsSinceEpoch(dirent->modtime, Qt::UTC));
fromDisk(subDir, subFi);
} else {
FileInfo fi(diskChild.fileName());
FileInfo fi(dirent->path);
fi.isDir = false;
fi.fileSize = diskChild.size();
fi.isDehydratedPlaceholder = isDehydratedPlaceholder(diskChild.absoluteFilePath());
fi.setLastModified(diskChild.lastModified());
fi.fileSize = dirent->size;
fi.isDehydratedPlaceholder = isDehydratedPlaceholder(dirent->path);
fi.setLastModified(QDateTime::fromSecsSinceEpoch(dirent->modtime, Qt::UTC));
if (fi.isDehydratedPlaceholder) {
fi.contentChar = '\0';
fi.contentSize = 0;
} else {
QFile f { diskChild.filePath() };
QFile f{dirent->path};
OC_ENFORCE(f.open(QFile::ReadOnly));
auto content = f.read(1);
if (content.size() == 0) {
qWarning() << "Empty file at:" << diskChild.filePath();
qWarning() << "Empty file at:" << dirent->path;
fi.contentChar = FileInfo::DefaultContentChar;
} else {
fi.contentChar = content.at(0);
Expand Down

0 comments on commit aa3684b

Please sign in to comment.