Skip to content

Commit 6a117be

Browse files
authored
Merge pull request #4970 from nextcloud/bugfix/file-name-clash
Improve handling of file name clashes
2 parents 38bc1e2 + 664a80c commit 6a117be

7 files changed

Lines changed: 33 additions & 7 deletions

File tree

src/gui/tray/activitylistmodel.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ QVariant ActivityListModel::data(const QModelIndex &index, int role) const
232232
|| a._status == SyncFileItem::Conflict
233233
|| a._status == SyncFileItem::Restoration
234234
|| a._status == SyncFileItem::FileLocked
235-
|| a._status == SyncFileItem::FileNameInvalid) {
235+
|| a._status == SyncFileItem::FileNameInvalid
236+
|| a._status == SyncFileItem::FileNameClash) {
236237
colorIconPath.append("state-warning.svg");
237238
return colorIconPath;
238239
} else if (a._status == SyncFileItem::FileIgnored) {
@@ -810,6 +811,22 @@ void ActivityListModel::slotTriggerDefaultAction(const int activityIndex)
810811
_currentInvalidFilenameDialog->open();
811812
ownCloudGui::raiseDialog(_currentInvalidFilenameDialog);
812813
return;
814+
} else if (activity._status == SyncFileItem::FileNameClash) {
815+
const auto folder = FolderMan::instance()->folder(activity._folder);
816+
const auto relPath = activity._fileAction == QStringLiteral("file_renamed") ? activity._renamedFile : activity._file;
817+
SyncJournalFileRecord record;
818+
819+
if (!folder || !folder->journalDb()->getFileRecord(relPath, &record)) {
820+
return;
821+
}
822+
823+
fetchPrivateLinkUrl(folder->accountState()->account(),
824+
relPath,
825+
record.numericFileId(),
826+
this,
827+
[](const QString &link) { Utility::openBrowser(link); }
828+
);
829+
return;
813830
}
814831

815832
if (!path.isEmpty()) {

src/libsync/bulkpropagatorjob.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -711,6 +711,7 @@ void BulkPropagatorJob::handleJobDoneErrors(SyncFileItemPtr item,
711711
case SyncFileItem::FileIgnored:
712712
case SyncFileItem::FileLocked:
713713
case SyncFileItem::FileNameInvalid:
714+
case SyncFileItem::FileNameClash:
714715
case SyncFileItem::NoStatus:
715716
case SyncFileItem::NormalError:
716717
case SyncFileItem::Restoration:

src/libsync/owncloudpropagator.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ void PropagateItemJob::done(SyncFileItem::Status statusArg, const QString &error
273273
case SyncFileItem::BlacklistedError:
274274
case SyncFileItem::FileLocked:
275275
case SyncFileItem::FileNameInvalid:
276+
case SyncFileItem::FileNameClash:
276277
// nothing
277278
break;
278279
}

src/libsync/progressdispatcher.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,8 @@ bool Progress::isWarningKind(SyncFileItem::Status kind)
9797
|| kind == SyncFileItem::FatalError || kind == SyncFileItem::FileIgnored
9898
|| kind == SyncFileItem::Conflict || kind == SyncFileItem::Restoration
9999
|| kind == SyncFileItem::DetailError || kind == SyncFileItem::BlacklistedError
100-
|| kind == SyncFileItem::FileLocked;
100+
|| kind == SyncFileItem::FileLocked || kind == SyncFileItem::FileNameInvalid
101+
|| kind == SyncFileItem::FileNameClash;
101102
}
102103

103104
bool Progress::isIgnoredKind(SyncFileItem::Status kind)

src/libsync/propagatedownload.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -528,14 +528,14 @@ void PropagateDownloadFile::startAfterIsEncryptedIsChecked()
528528
}
529529
if (_item->_type == ItemTypeVirtualFile) {
530530
if (propagator()->localFileNameClash(_item->_file)) {
531-
done(SyncFileItem::NormalError, tr("File %1 cannot be downloaded because of a local file name clash!").arg(QDir::toNativeSeparators(_item->_file)));
531+
done(SyncFileItem::FileNameClash, tr("File %1 cannot be downloaded because of a local file name clash!").arg(QDir::toNativeSeparators(_item->_file)));
532532
return;
533533
}
534534

535535
qCDebug(lcPropagateDownload) << "creating virtual file" << _item->_file;
536536
// do a klaas' case clash check.
537537
if (propagator()->localFileNameClash(_item->_file)) {
538-
done(SyncFileItem::NormalError, tr("File %1 can not be downloaded because of a local file name clash!").arg(QDir::toNativeSeparators(_item->_file)));
538+
done(SyncFileItem::FileNameClash, tr("File %1 can not be downloaded because of a local file name clash!").arg(QDir::toNativeSeparators(_item->_file)));
539539
return;
540540
}
541541
auto r = vfs->createPlaceholder(*_item);
@@ -633,7 +633,7 @@ void PropagateDownloadFile::startDownload()
633633

634634
// do a klaas' case clash check.
635635
if (propagator()->localFileNameClash(_item->_file)) {
636-
done(SyncFileItem::NormalError, tr("File %1 cannot be downloaded because of a local file name clash!").arg(QDir::toNativeSeparators(_item->_file)));
636+
done(SyncFileItem::FileNameClash, tr("File %1 cannot be downloaded because of a local file name clash!").arg(QDir::toNativeSeparators(_item->_file)));
637637
return;
638638
}
639639

@@ -1126,7 +1126,7 @@ void PropagateDownloadFile::downloadFinished()
11261126
// In case of file name clash, report an error
11271127
// This can happen if another parallel download saved a clashing file.
11281128
if (propagator()->localFileNameClash(_item->_file)) {
1129-
done(SyncFileItem::NormalError, tr("File %1 cannot be saved because of a local file name clash!").arg(QDir::toNativeSeparators(_item->_file)));
1129+
done(SyncFileItem::FileNameClash, tr("File %1 cannot be saved because of a local file name clash!").arg(QDir::toNativeSeparators(_item->_file)));
11301130
return;
11311131
}
11321132

src/libsync/syncfileitem.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ class OWNCLOUDSYNC_EXPORT SyncFileItem
7171
*/
7272
FileNameInvalid,
7373

74+
/**
75+
* There is a file name clash (e.g. attempting to download test.txt when TEST.TXT already exists
76+
* on a platform where the filesystem is case-insensitive
77+
*/
78+
FileNameClash,
79+
7480
/** For errors that should only appear in the error view.
7581
*
7682
* Some errors also produce a summary message. Usually displaying that message is

src/libsync/syncresult.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ void SyncResult::processCompletedItem(const SyncFileItemPtr &item)
141141
if (!_firstItemError) {
142142
_firstItemError = item;
143143
}
144-
} else if (item->_status == SyncFileItem::Conflict || item->_status == SyncFileItem::FileNameInvalid) {
144+
} else if (item->_status == SyncFileItem::Conflict || item->_status == SyncFileItem::FileNameInvalid || item->_status == SyncFileItem::FileNameClash) {
145145
if (item->_instruction == CSYNC_INSTRUCTION_CONFLICT) {
146146
_numNewConflictItems++;
147147
if (!_firstNewConflictItem) {

0 commit comments

Comments
 (0)