Skip to content

Commit

Permalink
Set remote filename when different from local filename
Browse files Browse the repository at this point in the history
  • Loading branch information
erikjv committed Jan 22, 2025
1 parent 266252f commit eef4228
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 7 deletions.
9 changes: 9 additions & 0 deletions src/common/filesystembase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -563,6 +563,15 @@ QString FileSystem::createPortableFileName(const QString &path, const QString &f
return QDir::cleanPath(path + QLatin1Char('/') + tmp);
}

QString FileSystem::localNormalizedFileName(const QString &name)
{
if (Utility::isMac()) {
return name.normalized(QString::NormalizationForm_C);
}

return name;
}

QString FileSystem::pathEscape(const QString &s)
{
QString tmp = s;
Expand Down
2 changes: 2 additions & 0 deletions src/common/filesystembase.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ namespace FileSystem {
*/
QString OCSYNC_EXPORT createPortableFileName(const QString &path, const QString &fileName, qsizetype reservedSize = 0);

QString OCSYNC_EXPORT localNormalizedFileName(const QString &name);

/*
* Replace path navigation elements from the string
*/
Expand Down
15 changes: 12 additions & 3 deletions src/libsync/discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,15 @@ void ProcessDirectoryJob::process()
};
std::map<QString, Entries> entries;
for (auto &e : _serverNormalQueryEntries) {
entries[e.name].serverEntry = std::move(e);
const QString localName = FileSystem::localNormalizedFileName(e.name);
auto it = entries.find(localName);
if (it == entries.end()) {
entries[localName].serverEntry = std::move(e);
} else {
// Normalization collision with another file
qCWarning(lcDisco) << "Normalization collision with another filename on the server for" << e.name;
// FIXME: generate an error for the user
}
}
_serverNormalQueryEntries.clear();

Expand Down Expand Up @@ -140,8 +148,7 @@ void ProcessDirectoryJob::process()
for (const auto &f : entries) {
const auto &e = f.second;

PathTuple path;
path = _currentFolder.addName(e.nameOverride.isEmpty() ? f.first : e.nameOverride);
PathTuple path = _currentFolder.addName(e.nameOverride.isEmpty() ? f.first : e.nameOverride, f.second.serverEntry.name);

if (isVfsWithSuffix()) {
// Without suffix vfs the paths would be good. But since the dbEntry and localEntry
Expand Down Expand Up @@ -336,6 +343,8 @@ void ProcessDirectoryJob::processFile(const PathTuple &path,

auto item = SyncFileItem::fromSyncJournalFileRecord(dbEntry);
item->setLocalName(path._target);
item->maybeSetRemoteName(path._server);

item->_originalFile = path._original;
item->_previousSize = dbEntry._fileSize;
item->_previousModtime = dbEntry._modtime;
Expand Down
8 changes: 4 additions & 4 deletions src/libsync/discovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,16 +115,16 @@ class ProcessDirectoryJob : public QObject
{
return base.isEmpty() ? name : base + QLatin1Char('/') + name;
}
PathTuple addName(const QString &name) const
PathTuple addName(const QString &localName, const QString &serverName) const
{
PathTuple result;
result._original = pathAppend(_original, name);
result._original = pathAppend(_original, localName);
auto buildString = [&](const QString &other) {
// Optimize by trying to keep all string implicitly shared if they are the same (common case)
return other == _original ? result._original : pathAppend(other, name);
return other == _original ? result._original : pathAppend(other, localName);
};
result._target = buildString(_target);
result._server = buildString(_server);
result._server = localName == serverName ? buildString(_server) : pathAppend(_server, serverName);
result._local = buildString(_local);
return result;
}
Expand Down
6 changes: 6 additions & 0 deletions src/libsync/syncfileitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,12 @@ class OWNCLOUDSYNC_EXPORT SyncFileItem

QString remoteName() const { return _remoteName.isEmpty() ? _localName : _remoteName; }
QString rawRemoteName() const { return _remoteName; }
void maybeSetRemoteName(const QString &remoteName)
{
if (!remoteName.isEmpty() && remoteName != _localName) {
_remoteName = remoteName;
}
}

private:
/** The syncfolder-relative filesystem path that the operation is about
Expand Down

0 comments on commit eef4228

Please sign in to comment.