mirror of
https://github.com/nextcloud/desktop.git
synced 2025-10-26 11:17:43 +00:00
Add KeepBothVersions as a possible solution to ConflictSolver
Signed-off-by: Kevin Ottens <kevin.ottens@nextcloud.com>
This commit is contained in:
parent
4fdb203cdb
commit
67e81fcd0f
@ -17,6 +17,7 @@
|
||||
#include <QFileDialog>
|
||||
#include <QMessageBox>
|
||||
|
||||
#include "common/utility.h"
|
||||
#include "filesystem.h"
|
||||
|
||||
namespace OCC {
|
||||
@ -46,6 +47,8 @@ bool ConflictSolver::exec(ConflictSolver::Solution solution)
|
||||
return overwriteRemoteVersion();
|
||||
case KeepRemoteVersion:
|
||||
return deleteLocalVersion();
|
||||
case KeepBothVersions:
|
||||
return renameLocalVersion();
|
||||
}
|
||||
Q_UNREACHABLE();
|
||||
return false;
|
||||
@ -95,6 +98,44 @@ bool ConflictSolver::deleteLocalVersion()
|
||||
}
|
||||
}
|
||||
|
||||
bool ConflictSolver::renameLocalVersion()
|
||||
{
|
||||
if (_localVersionFilename.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
QFileInfo info(_localVersionFilename);
|
||||
if (!info.exists()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const auto renamePattern = [=] {
|
||||
auto result = QString::fromUtf8(OCC::Utility::conflictFileBaseNameFromPattern(_localVersionFilename.toUtf8()));
|
||||
const auto dotIndex = result.lastIndexOf('.');
|
||||
return QString(result.left(dotIndex) + "_%1" + result.mid(dotIndex));
|
||||
}();
|
||||
|
||||
const auto targetFilename = [=] {
|
||||
uint i = 1;
|
||||
auto result = renamePattern.arg(i);
|
||||
while (QFileInfo::exists(result)) {
|
||||
Q_ASSERT(i > 0);
|
||||
i++;
|
||||
result = renamePattern.arg(i);
|
||||
}
|
||||
return result;
|
||||
}();
|
||||
|
||||
QString error;
|
||||
if (FileSystem::uncheckedRenameReplace(_localVersionFilename, targetFilename, &error)) {
|
||||
return true;
|
||||
} else {
|
||||
qCWarning(lcConflict) << "Rename error:" << error;
|
||||
QMessageBox::warning(_parentWidget, tr("Error"), tr("Moving file failed:\n\n%1").arg(error));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool ConflictSolver::overwriteRemoteVersion()
|
||||
{
|
||||
if (_localVersionFilename.isEmpty()) {
|
||||
|
||||
@ -29,7 +29,8 @@ class ConflictSolver : public QObject
|
||||
public:
|
||||
enum Solution {
|
||||
KeepLocalVersion,
|
||||
KeepRemoteVersion
|
||||
KeepRemoteVersion,
|
||||
KeepBothVersions
|
||||
};
|
||||
|
||||
explicit ConflictSolver(QWidget *parent = nullptr);
|
||||
@ -49,6 +50,7 @@ signals:
|
||||
|
||||
private:
|
||||
bool deleteLocalVersion();
|
||||
bool renameLocalVersion();
|
||||
bool overwriteRemoteVersion();
|
||||
|
||||
QWidget *_parentWidget;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user