Skip to content

Commit dde1dd1

Browse files
committed
Improve installer rollback logic
1 parent 6cc61e6 commit dde1dd1

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

Client/loader/Install.cpp

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
static std::string ROLLBACK_NAME = "rollback.step";
1919
static char ARCHIVE_PASSWORD[] = "mta";
2020

21+
constexpr DWORD OPERATION_RETRY_DELAY_IN_MS = 100;
22+
2123
struct ChecksumFile
2224
{
2325
std::optional<uint32_t> checksum{};
@@ -410,6 +412,9 @@ static auto RunRollback(std::vector<InstallableFile>& files) -> size_t
410412

411413
for (InstallableFile& file : files)
412414
{
415+
if (file.targetFile == file.backupFile)
416+
continue;
417+
413418
int attempts = 0;
414419
int checksums = 0;
415420
bool success = false;
@@ -447,8 +452,7 @@ static auto RunRollback(std::vector<InstallableFile>& files) -> size_t
447452
TerminateFileLockingProcesses(file.backupFile.absolutePath, file.relativePath);
448453
}
449454

450-
// Wait for an arbitrary amount of time before retrying.
451-
Sleep(100);
455+
Sleep(OPERATION_RETRY_DELAY_IN_MS);
452456
}
453457
}
454458

@@ -686,8 +690,7 @@ static int RunInstall()
686690
TerminateFileLockingProcesses(file.backupFile.absolutePath, file.relativePath);
687691
}
688692

689-
// Wait for an arbitrary amount of time before retrying.
690-
Sleep(100);
693+
Sleep(OPERATION_RETRY_DELAY_IN_MS);
691694
}
692695
}
693696

@@ -760,8 +763,7 @@ static int RunInstall()
760763
TerminateFileLockingProcesses(file.sourceFile.absolutePath, file.relativePath);
761764
}
762765

763-
// Wait for an arbitrary amount of time before retrying.
764-
Sleep(100);
766+
Sleep(OPERATION_RETRY_DELAY_IN_MS);
765767
}
766768
}
767769

@@ -778,6 +780,9 @@ static int RunInstall()
778780

779781
if (!success)
780782
{
783+
// Update the target file checksum for rollback, because we don't know if the target file was modified in the install process.
784+
file.targetFile.ComputeChecksum();
785+
781786
bool exists = FileExists(file.sourceFile.absolutePath);
782787
AddReportLog(5055, SString("RunInstall: Unable to install '%s' (exists: %d, attempts: %d, checksums: %d)", file.relativePath.c_str(), exists,
783788
attempts, checksums));
@@ -866,6 +871,9 @@ bool InstallFiles(bool showProgressWindow)
866871

867872
bool ExtractFiles(const std::string& archivePath, bool withManifest)
868873
{
874+
if (archivePath.empty() || !FileExists(archivePath))
875+
return false;
876+
869877
std::vector<ManifestFile> files;
870878

871879
if (!ExtractArchiveFiles(archivePath, files, ARCHIVE_PASSWORD))
@@ -905,6 +913,9 @@ SString CheckOnRestartCommand()
905913
// Update
906914
//
907915

916+
if (strFile.empty() || !FileExists(strFile))
917+
return "FileMissing";
918+
908919
// Make temp path name and go there
909920
SString strArchivePath, strArchiveName;
910921
strFile.Split("\\", &strArchivePath, &strArchiveName, -1);

0 commit comments

Comments
 (0)