2016-10-03 04:25:54 +05:30
|
|
|
#include "InstanceCreationTask.h"
|
|
|
|
|
2022-07-08 05:01:24 +05:30
|
|
|
#include <QDebug>
|
fix: move file deletion to the end of the instance update
This makes it harder for problems in the updating process to affect the
current instance. Network issues, for instance, will no longer put the
instance in an invalid state.
Still, a possible improvement to this would be passing that logic to
InstanceStaging instead, to be handled with the instance commiting
directly. However, as it is now, the code would become very spaguetti-y,
and given that the override operation in the commiting could also put
the instance into an invalid state, it seems to me that, in order to
fully error-proof this, we would need to do a copy operation on the
whole instance, in order to modify the copy, and only in the end
override everything an once with a rename. That also has the possibility
of corrupting the instance if done without super care, however, so I
think we may need to instead create an automatic backup system, with an
undo command of sorts, or something like that. This doesn't seem very
trivial though, so it'll probably need to wait until another PR. In the
meantime, the user is advised to always backup their instances before
doing this kind of action, as always.
What a long commit message o.O
Signed-off-by: flow <flowlnlnln@gmail.com>
2022-08-06 05:56:02 +05:30
|
|
|
#include <QFile>
|
2016-10-03 04:25:54 +05:30
|
|
|
|
2022-08-01 02:51:59 +05:30
|
|
|
InstanceCreationTask::InstanceCreationTask() = default;
|
2016-10-03 04:25:54 +05:30
|
|
|
|
|
|
|
void InstanceCreationTask::executeTask()
|
|
|
|
{
|
2022-08-21 17:56:27 +05:30
|
|
|
setAbortable(true);
|
2022-08-06 05:55:21 +05:30
|
|
|
|
2022-08-01 02:51:59 +05:30
|
|
|
if (updateInstance()) {
|
|
|
|
emitSucceeded();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-08-01 04:59:12 +05:30
|
|
|
// When the user aborted in the update stage.
|
|
|
|
if (m_abort) {
|
|
|
|
emitAborted();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
fix: move file deletion to the end of the instance update
This makes it harder for problems in the updating process to affect the
current instance. Network issues, for instance, will no longer put the
instance in an invalid state.
Still, a possible improvement to this would be passing that logic to
InstanceStaging instead, to be handled with the instance commiting
directly. However, as it is now, the code would become very spaguetti-y,
and given that the override operation in the commiting could also put
the instance into an invalid state, it seems to me that, in order to
fully error-proof this, we would need to do a copy operation on the
whole instance, in order to modify the copy, and only in the end
override everything an once with a rename. That also has the possibility
of corrupting the instance if done without super care, however, so I
think we may need to instead create an automatic backup system, with an
undo command of sorts, or something like that. This doesn't seem very
trivial though, so it'll probably need to wait until another PR. In the
meantime, the user is advised to always backup their instances before
doing this kind of action, as always.
What a long commit message o.O
Signed-off-by: flow <flowlnlnln@gmail.com>
2022-08-06 05:56:02 +05:30
|
|
|
if (!createInstance()) {
|
|
|
|
if (m_abort)
|
|
|
|
return;
|
2022-08-01 02:51:59 +05:30
|
|
|
|
fix: move file deletion to the end of the instance update
This makes it harder for problems in the updating process to affect the
current instance. Network issues, for instance, will no longer put the
instance in an invalid state.
Still, a possible improvement to this would be passing that logic to
InstanceStaging instead, to be handled with the instance commiting
directly. However, as it is now, the code would become very spaguetti-y,
and given that the override operation in the commiting could also put
the instance into an invalid state, it seems to me that, in order to
fully error-proof this, we would need to do a copy operation on the
whole instance, in order to modify the copy, and only in the end
override everything an once with a rename. That also has the possibility
of corrupting the instance if done without super care, however, so I
think we may need to instead create an automatic backup system, with an
undo command of sorts, or something like that. This doesn't seem very
trivial though, so it'll probably need to wait until another PR. In the
meantime, the user is advised to always backup their instances before
doing this kind of action, as always.
What a long commit message o.O
Signed-off-by: flow <flowlnlnln@gmail.com>
2022-08-06 05:56:02 +05:30
|
|
|
qWarning() << "Instance creation failed!";
|
|
|
|
if (!m_error_message.isEmpty())
|
|
|
|
qWarning() << "Reason: " << m_error_message;
|
|
|
|
emitFailed(tr("Error while creating new instance."));
|
2022-07-08 05:01:24 +05:30
|
|
|
return;
|
2018-07-15 18:21:05 +05:30
|
|
|
}
|
2022-07-08 05:01:24 +05:30
|
|
|
|
fix: move file deletion to the end of the instance update
This makes it harder for problems in the updating process to affect the
current instance. Network issues, for instance, will no longer put the
instance in an invalid state.
Still, a possible improvement to this would be passing that logic to
InstanceStaging instead, to be handled with the instance commiting
directly. However, as it is now, the code would become very spaguetti-y,
and given that the override operation in the commiting could also put
the instance into an invalid state, it seems to me that, in order to
fully error-proof this, we would need to do a copy operation on the
whole instance, in order to modify the copy, and only in the end
override everything an once with a rename. That also has the possibility
of corrupting the instance if done without super care, however, so I
think we may need to instead create an automatic backup system, with an
undo command of sorts, or something like that. This doesn't seem very
trivial though, so it'll probably need to wait until another PR. In the
meantime, the user is advised to always backup their instances before
doing this kind of action, as always.
What a long commit message o.O
Signed-off-by: flow <flowlnlnln@gmail.com>
2022-08-06 05:56:02 +05:30
|
|
|
// If this is set, it means we're updating an instance. So, we now need to remove the
|
|
|
|
// files scheduled to, and we'd better not let the user abort in the middle of it, since it'd
|
|
|
|
// put the instance in an invalid state.
|
|
|
|
if (shouldOverride()) {
|
2022-08-21 17:56:27 +05:30
|
|
|
setAbortable(false);
|
fix: move file deletion to the end of the instance update
This makes it harder for problems in the updating process to affect the
current instance. Network issues, for instance, will no longer put the
instance in an invalid state.
Still, a possible improvement to this would be passing that logic to
InstanceStaging instead, to be handled with the instance commiting
directly. However, as it is now, the code would become very spaguetti-y,
and given that the override operation in the commiting could also put
the instance into an invalid state, it seems to me that, in order to
fully error-proof this, we would need to do a copy operation on the
whole instance, in order to modify the copy, and only in the end
override everything an once with a rename. That also has the possibility
of corrupting the instance if done without super care, however, so I
think we may need to instead create an automatic backup system, with an
undo command of sorts, or something like that. This doesn't seem very
trivial though, so it'll probably need to wait until another PR. In the
meantime, the user is advised to always backup their instances before
doing this kind of action, as always.
What a long commit message o.O
Signed-off-by: flow <flowlnlnln@gmail.com>
2022-08-06 05:56:02 +05:30
|
|
|
setStatus(tr("Removing old conflicting files..."));
|
|
|
|
qDebug() << "Removing old files";
|
|
|
|
|
|
|
|
for (auto path : m_files_to_remove) {
|
|
|
|
if (!QFile::exists(path))
|
|
|
|
continue;
|
|
|
|
qDebug() << "Removing" << path;
|
|
|
|
if (!QFile::remove(path)) {
|
|
|
|
qCritical() << "Couldn't remove the old conflicting files.";
|
|
|
|
emitFailed(tr("Failed to remove old conflicting files."));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
emitSucceeded();
|
|
|
|
return;
|
2016-10-03 04:25:54 +05:30
|
|
|
}
|