Skip to content

Commit 5e44cb4

Browse files
authored
Merge pull request Squirrel#1862 from q837477816/develop
Fix app can not restart after an unexpected exit during the apply releases
2 parents 0ee9447 + f900ac4 commit 5e44cb4

2 files changed

Lines changed: 21 additions & 0 deletions

File tree

src/Squirrel/UpdateManager.ApplyReleases.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,13 +308,22 @@ Task<string> installPackageToAppDir(UpdateInfo updateInfo, ReleaseEntry release,
308308

309309
target.Create();
310310

311+
// Create the .not-finished file before extraction is started
312+
var notFinishedFilePath = Path.Combine(target.FullName, ".not-finished");
313+
File.WriteAllText(notFinishedFilePath, "");
314+
311315
this.Log().Info("Writing files to app directory: {0}", target.FullName);
312316
await ReleasePackage.ExtractZipForInstall(
313317
Path.Combine(updateInfo.PackageDirectory, release.Filename),
314318
target.FullName,
315319
rootAppDirectory,
316320
progressCallback);
317321

322+
// Delete the .not-finished file after extraction is completed
323+
this.ErrorIfThrows(() => {
324+
File.Delete(notFinishedFilePath);
325+
}, "Couldn't delete file: " + notFinishedFilePath);
326+
318327
return target.FullName;
319328
});
320329
}

src/StubExecutable/StubExecutable.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88

99
using namespace std;
1010

11+
bool FileExists(const std::wstring& filePath) {
12+
DWORD fileAttributes = GetFileAttributes(filePath.c_str());
13+
return (fileAttributes != INVALID_FILE_ATTRIBUTES) && !(fileAttributes & FILE_ATTRIBUTE_DIRECTORY);
14+
}
15+
1116
wchar_t* FindRootAppDir()
1217
{
1318
wchar_t* ourDirectory = new wchar_t[MAX_PATH];
@@ -67,6 +72,13 @@ std::wstring FindLatestAppDir()
6772

6873
version::Semver200_version thisVer(s);
6974

75+
// Skip the directory which contains a .not-finished file
76+
std::wstring appFolder = fileInfo.cFileName;
77+
std::wstring dirPath = ourDir.substr(0, ourDir.size() - 5) + appFolder;
78+
if (FileExists(dirPath + L"\\.not-finished")) {
79+
continue;
80+
}
81+
7082
if (thisVer > acc) {
7183
acc = thisVer;
7284
acc_s = appVer;

0 commit comments

Comments
 (0)