Skip to content

Commit

Permalink
Display local file name in case clash warning
Browse files Browse the repository at this point in the history
Fixes: #8609
  • Loading branch information
TheOneRing committed May 11, 2021
1 parent c6ea448 commit fa2b144
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 19 deletions.
6 changes: 6 additions & 0 deletions changelog/unreleased/8609
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Enhancement: Mention the local file name when a file name clash occurs

We now display the name of the file we detected the clash with.

https://github.com/owncloud/client/issues/8609
https://github.com/owncloud/client/pull/8630
14 changes: 6 additions & 8 deletions src/libsync/owncloudpropagator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,7 @@ void OwncloudPropagator::setSyncOptions(const SyncOptions &syncOptions)
_chunkSize = syncOptions._initialChunkSize;
}

bool OwncloudPropagator::localFileNameClash(const QString &relFile)
Result<QString, bool> OwncloudPropagator::localFileNameClash(const QString &relFile)
{
const QString file(_localDir + relFile);
OC_ASSERT(!file.isEmpty());
Expand All @@ -526,23 +526,21 @@ bool OwncloudPropagator::localFileNameClash(const QString &relFile)
const QString cName = fileInfo.canonicalFilePath().normalized(QString::NormalizationForm_C);
if (file != cName && !cName.endsWith(relFile, Qt::CaseSensitive)) {
qCWarning(lcPropagator) << "Detected case clash between" << file << "and" << cName;
return true;
return cName;
}
}
#elif defined(Q_OS_WIN)
WIN32_FIND_DATA FindFileData;
HANDLE hFind;

hFind = FindFirstFileW(reinterpret_cast<const wchar_t *>(FileSystem::longWinPath(file).utf16()), &FindFileData);
if (hFind == INVALID_HANDLE_VALUE) {
// returns false.
} else {
const QString realFileName = QString::fromWCharArray(FindFileData.cFileName);
if (hFind != INVALID_HANDLE_VALUE) {
const QString realFileName = _localDir + QString::fromWCharArray(FindFileData.cFileName);
FindClose(hFind);

if (!file.endsWith(realFileName, Qt::CaseSensitive)) {
qCWarning(lcPropagator) << "Detected case clash between" << file << "and" << realFileName;
return true;
return realFileName;
}
}
#else
Expand All @@ -552,7 +550,7 @@ bool OwncloudPropagator::localFileNameClash(const QString &relFile)
const QString fn = fileInfo.fileName();
const QStringList list = fileInfo.dir().entryList({ fn });
if (list.count() > 1 || (list.count() == 1 && list[0] != fn)) {
return true;
return list[0];
}
#endif
}
Expand Down
3 changes: 2 additions & 1 deletion src/libsync/owncloudpropagator.h
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,9 @@ class OWNCLOUDSYNC_EXPORT OwncloudPropagator : public QObject

/** Check whether a download would clash with an existing file
* in filesystems that are only case-preserving.
* Returns the path of the clashed file
*/
bool localFileNameClash(const QString &relfile);
Result<QString, bool> localFileNameClash(const QString &relfile);

/** Check whether a file is properly accessible for upload.
*
Expand Down
12 changes: 6 additions & 6 deletions src/libsync/propagatedownload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -382,8 +382,8 @@ void PropagateDownloadFile::start()
if (_item->_type == ItemTypeVirtualFile) {
qCDebug(lcPropagateDownload) << "creating virtual file" << _item->_file;
// do a klaas' case clash check.
if (propagator()->localFileNameClash(_item->_file)) {
done(SyncFileItem::NormalError, tr("File %1 can not be downloaded because of a local file name clash!").arg(QDir::toNativeSeparators(_item->_file)));
if (auto clash = propagator()->localFileNameClash(_item->_file)) {
done(SyncFileItem::NormalError, tr("File %1 can not be downloaded because of a local file name clash with %2!").arg(QDir::toNativeSeparators(_item->_file), QDir::toNativeSeparators(clash.get())));
return;
}
auto r = vfs->createPlaceholder(*_item);
Expand Down Expand Up @@ -460,8 +460,8 @@ void PropagateDownloadFile::startDownload()
return;

// do a klaas' case clash check.
if (propagator()->localFileNameClash(_item->_file)) {
done(SyncFileItem::NormalError, tr("File %1 can not be downloaded because of a local file name clash!").arg(QDir::toNativeSeparators(_item->_file)));
if (auto clash = propagator()->localFileNameClash(_item->_file)) {
done(SyncFileItem::NormalError, tr("File %1 can not be downloaded because of a local file name clash with %2!").arg(QDir::toNativeSeparators(_item->_file), QDir::toNativeSeparators(clash.get())));
return;
}

Expand Down Expand Up @@ -892,8 +892,8 @@ void PropagateDownloadFile::downloadFinished()

// In case of file name clash, report an error
// This can happen if another parallel download saved a clashing file.
if (propagator()->localFileNameClash(_item->_file)) {
done(SyncFileItem::NormalError, tr("File %1 cannot be saved because of a local file name clash!").arg(QDir::toNativeSeparators(_item->_file)));
if (auto clash = propagator()->localFileNameClash(_item->_file)) {
done(SyncFileItem::NormalError, tr("File %1 cannot be saved because of a local file name clash with %2!").arg(QDir::toNativeSeparators(_item->_file), QDir::toNativeSeparators(clash.get())));
return;
}

Expand Down
8 changes: 4 additions & 4 deletions src/libsync/propagatorjobs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,8 @@ void PropagateLocalRemove::start()
const QString filename = propagator()->fullLocalPath(_item->_file);
qCDebug(lcPropagateLocalRemove) << filename;

if (propagator()->localFileNameClash(_item->_file)) {
done(SyncFileItem::NormalError, tr("Could not remove %1 because of a local file name clash").arg(QDir::toNativeSeparators(filename)));
if (auto clash = propagator()->localFileNameClash(_item->_file)) {
done(SyncFileItem::NormalError, tr("Could not remove %1 because of a local file name clash with %2!").arg(QDir::toNativeSeparators(filename), QDir::toNativeSeparators(clash.get())));
return;
}

Expand Down Expand Up @@ -156,9 +156,9 @@ void PropagateLocalMkdir::start()
}
}

if (Utility::fsCasePreserving() && propagator()->localFileNameClash(_item->_file)) {
if (auto clash = propagator()->localFileNameClash(_item->_file)) {
qCWarning(lcPropagateLocalMkdir) << "New folder to create locally already exists with different case:" << _item->_file;
done(SyncFileItem::NormalError, tr("Attention, possible case sensitivity clash with %1").arg(newDirStr));
done(SyncFileItem::NormalError, tr("Attention, possible case sensitivity clash of %1 with %2").arg(QDir::toNativeSeparators(clash.get()), newDirStr));
return;
}
emit propagator()->touchedFile(newDirStr);
Expand Down

0 comments on commit fa2b144

Please sign in to comment.