diff --git a/src/Lib/AbstractDocument.hh b/src/Lib/AbstractDocument.hh index 9142bc4b6741f34fe7585a56bf3372ef9de092fb..51d951016a85c921bdbc587e1592ee7e6b616c91 100644 --- a/src/Lib/AbstractDocument.hh +++ b/src/Lib/AbstractDocument.hh @@ -43,11 +43,21 @@ protected: dirOp.mkpath(newAbsDirPath); } - if (QFile::copy(oldFile.absoluteFilePath(), newFile.absoluteFilePath())) - return success(); + if (newFile.exists()) { + qWarning() << "Deleting the already existing" << newFile; + if (!dirOp.remove(newFile.absoluteFilePath())) + throw std::runtime_error("Failed to remove " + + newFile.absoluteFilePath().toStdString()); + } + + if (QFile::copy(oldFile.absoluteFilePath(), newFile.absoluteFilePath())) { + success(); + save(); + } - throw std::runtime_error("Failed to copy " + oldFile.absoluteFilePath().toStdString() + - " to " + newFile.absoluteFilePath().toStdString()); + else + throw std::runtime_error("Failed to copy " + oldFile.absoluteFilePath().toStdString() + + " to " + newFile.absoluteFilePath().toStdString()); } // Automate a part of the rename process, just need to provide a "success" @@ -64,11 +74,23 @@ protected: dirOp.mkpath(newAbsDirPath); } - if (dirOp.rename(oldFile.absoluteFilePath(), newFile.absoluteFilePath())) - return success(); + if (newFile.exists()) { + qWarning() << "Deleting the already existing" << newFile; + dirOp.remove(newFile.absoluteFilePath()); + if (!dirOp.remove(newFile.absoluteFilePath())) + throw std::runtime_error("Failed to remove " + + newFile.absoluteFilePath().toStdString()); + } + + if (dirOp.rename(oldFile.absoluteFilePath(), newFile.absoluteFilePath())) { + success(); + save(); + } - throw std::runtime_error("Failed to rename " + oldFile.absoluteFilePath().toStdString() + - " to " + newFile.absoluteFilePath().toStdString()); + else + throw std::runtime_error("Failed to rename " + + oldFile.absoluteFilePath().toStdString() + " to " + + newFile.absoluteFilePath().toStdString()); } Type type;