Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
Write temp file to mark staging directory as incomplete until extract…
Browse files Browse the repository at this point in the history
…ion is finished (fixes #182)
  • Loading branch information
caesay committed Nov 4, 2023
1 parent c46f44a commit 5837b9a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/Squirrel/UpdateManager.ApplyReleases.cs
Original file line number Diff line number Diff line change
Expand Up @@ -299,13 +299,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).ConfigureAwait(false);
// Delete the .not-finished file after extraction is completed
this.ErrorIfThrows(() => {
File.Delete(notFinishedFilePath);
}, "Couldn't delete file: " + notFinishedFilePath);
return target.FullName;
});
}
Expand Down
13 changes: 13 additions & 0 deletions src/StubExecutable/StubExecutable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,12 @@

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 +73,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
2 changes: 1 addition & 1 deletion src/Update/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ static void ProcessStart(string exeName, string arguments, bool shouldWait)
Utility.AppDirForRelease(appDir, x),
Utility.AppDirForVersion(appDir, new SemanticVersion(x.Version.Version.Major, x.Version.Version.Minor, x.Version.Version.Build, ""))
})
.FirstOrDefault(x => Directory.Exists(x));
.FirstOrDefault(x => Directory.Exists(x) && !File.Exists(Path.Combine(x, ".not-finished")));

// Check for the EXE name they want
var targetExe = new FileInfo(Path.Combine(latestAppDir, exeName.Replace("%20", " ")));
Expand Down

0 comments on commit 5837b9a

Please sign in to comment.