refactor: use std::filesystem::rename insted of copy and then moving.
Signed-off-by: Rachel Powers <508861+Ryex@users.noreply.github.com>
This commit is contained in:
parent
3691f3a296
commit
c470f05abf
@ -213,6 +213,22 @@ bool copy::operator()(const QString& offset, bool dryRun)
|
|||||||
return err.value() == 0;
|
return err.value() == 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool move(const QString& source, const QString& dest)
|
||||||
|
{
|
||||||
|
std::error_code err;
|
||||||
|
|
||||||
|
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;
|
||||||
|
qDebug() << "Destination file:" << dest;
|
||||||
|
}
|
||||||
|
|
||||||
|
return err.value() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
bool deletePath(QString path)
|
bool deletePath(QString path)
|
||||||
{
|
{
|
||||||
std::error_code err;
|
std::error_code err;
|
||||||
|
@ -121,6 +121,14 @@ class copy : public QObject {
|
|||||||
int m_copied;
|
int m_copied;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief moves a file by renaming it
|
||||||
|
* @param source source file path
|
||||||
|
* @param dest destination filepath
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
bool move(const QString& source, const QString& dest);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete a folder recursively
|
* Delete a folder recursively
|
||||||
*/
|
*/
|
||||||
|
@ -539,19 +539,6 @@ void FlameCreationTask::copyBlockedMods(QList<BlockedMod> const& blocked_mods)
|
|||||||
setAbortable(true);
|
setAbortable(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool moveFile(QString src, QString dst)
|
|
||||||
{
|
|
||||||
if (!FS::copy(src, dst)()) { // copy
|
|
||||||
qDebug() << "Copy of" << src << "to" << dst << "failed!";
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
if (!FS::deletePath(src)) { // remove original
|
|
||||||
qDebug() << "Deletion of" << src << "failed!";
|
|
||||||
return false;
|
|
||||||
};
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
void FlameCreationTask::validateZIPResouces()
|
void FlameCreationTask::validateZIPResouces()
|
||||||
{
|
{
|
||||||
@ -567,7 +554,7 @@ void FlameCreationTask::validateZIPResouces()
|
|||||||
qDebug() << "Target folder of" << fileName << "is incorrect, it belongs in" << realTarget;
|
qDebug() << "Target folder of" << fileName << "is incorrect, it belongs in" << realTarget;
|
||||||
auto destPath = FS::PathCombine(m_stagingPath, "minecraft", realTarget, fileName);
|
auto destPath = FS::PathCombine(m_stagingPath, "minecraft", realTarget, fileName);
|
||||||
qDebug() << "Moving" << localPath << "to" << destPath;
|
qDebug() << "Moving" << localPath << "to" << destPath;
|
||||||
if (moveFile(localPath, destPath)) {
|
if (FS::move(localPath, destPath)) {
|
||||||
return destPath;
|
return destPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user