added special case for windows

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2023-11-05 16:47:33 +02:00
parent 5afe6600ee
commit 1d67fc6646
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318

View File

@ -643,6 +643,19 @@ void ExternalLinkFileProcess::runLinkFile()
qDebug() << "Process exited";
}
bool moveByCopy(const QString& source, const QString& dest)
{
if (!copy(source, dest)()) { // copy
qDebug() << "Copy of" << source << "to" << dest << "failed!";
return false;
}
if (!deletePath(source)) { // remove original
qDebug() << "Deletion of" << source << "failed!";
return false;
};
return true;
}
bool move(const QString& source, const QString& dest)
{
std::error_code err;
@ -650,12 +663,14 @@ bool move(const QString& source, const QString& dest)
ensureFilePathExists(dest);
fs::rename(StringUtils::toStdString(source), StringUtils::toStdString(dest), err);
if (err) {
qWarning() << "Failed to move file:" << QString::fromStdString(err.message());
qDebug() << "Source file:" << source << ";Destination file:" << dest;
if (err.value() != 0) {
if (moveByCopy(source, dest))
return true;
qDebug() << "Move of" << source << "to" << dest << "failed!";
qWarning() << "Failed to move file:" << QString::fromStdString(err.message()) << QString::number(err.value());
return false;
}
return err.value() == 0;
return true;
}
bool deletePath(QString path)