Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix app can not restart after an unexpected exit during the apply releases #1862

Merged
merged 4 commits into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions src/Squirrel/UpdateManager.ApplyReleases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -308,13 +308,22 @@ Task<string> installPackageToAppDir(UpdateInfo updateInfo, ReleaseEntry release,

target.Create();

// Create the .not-finished file before extraction is started
var notFinishedFilePath = Path.Combine(target.FullName, ".not-finished");
File.WriteAllText(notFinishedFilePath, "");

this.Log().Info("Writing files to app directory: {0}", target.FullName);
await ReleasePackage.ExtractZipForInstall(
Path.Combine(updateInfo.PackageDirectory, release.Filename),
target.FullName,
rootAppDirectory,
progressCallback);

// Delete the .not-finished file after extraction is completed
if (File.Exists(notFinishedFilePath)) {
DamonYu6 marked this conversation as resolved.
Show resolved Hide resolved
File.Delete(notFinishedFilePath);
}

return target.FullName;
});
}
Expand Down
12 changes: 12 additions & 0 deletions src/StubExecutable/StubExecutable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@

using namespace std;

bool FileExists(const std::wstring& filePath) {
DWORD fileAttributes = GetFileAttributes(filePath.c_str());
return (fileAttributes != INVALID_FILE_ATTRIBUTES) && !(fileAttributes & FILE_ATTRIBUTE_DIRECTORY);
}

wchar_t* FindRootAppDir()
{
wchar_t* ourDirectory = new wchar_t[MAX_PATH];
Expand Down Expand Up @@ -67,6 +72,13 @@ std::wstring FindLatestAppDir()

version::Semver200_version thisVer(s);

// Skip the directory which contains a .not-finished file
std::wstring appFolder = fileInfo.cFileName;
std::wstring dirPath = ourDir.substr(0, ourDir.size() - 5) + appFolder;
if (FileExists(dirPath + L"\\.not-finished")) {
DamonYu6 marked this conversation as resolved.
Show resolved Hide resolved
continue;
}

if (thisVer > acc) {
acc = thisVer;
acc_s = appVer;
Expand Down