Skip to content

Commit

Permalink
Merge pull request #1862 from q837477816/develop
Browse files Browse the repository at this point in the history
Fix app can not restart after an unexpected exit during the apply releases
  • Loading branch information
anaisbetts authored Aug 1, 2023
2 parents 0ee9447 + f900ac4 commit 5e44cb4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
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
this.ErrorIfThrows(() => {
File.Delete(notFinishedFilePath);
}, "Couldn't delete file: " + 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")) {
continue;
}

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

0 comments on commit 5e44cb4

Please sign in to comment.