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 permission check #111

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all 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
21 changes: 12 additions & 9 deletions src/NAppUpdate.Framework/Tasks/FileUpdateTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,6 @@ public override TaskExecutionStatus Execute(bool coldRun)
return TaskExecutionStatus.Successful; // Errorneous case, but there's nothing to prepare to, and by default we prefer a noop over an error
}

var dirName = Path.GetDirectoryName(_destinationFile);
if (!Directory.Exists(dirName))
{
Utils.FileSystem.CreateDirectoryStructure(dirName, false);
}

// Create a backup copy if target exists
if (_backupFile == null && File.Exists(_destinationFile))
{
Expand Down Expand Up @@ -113,7 +107,12 @@ public override TaskExecutionStatus Execute(bool coldRun)

try
{
if (File.Exists(_destinationFile))
var dirName = Path.GetDirectoryName(_destinationFile);
if (!Directory.Exists(dirName))
{
Utils.FileSystem.CreateDirectoryStructure(dirName, false);
}
if (File.Exists(_destinationFile))
{
FileSystem.CopyAccessControl(new FileInfo(_destinationFile), new FileInfo(_tempFile));

Expand All @@ -139,8 +138,12 @@ public override TaskExecutionStatus Execute(bool coldRun)
// If we got thus far, we have completed execution
return TaskExecutionStatus.Successful;

// Otherwise, figure out what restart method to use
if (File.Exists(_destinationFile) && !Utils.PermissionsCheck.HaveWritePermissionsForFileOrFolder(_destinationFile))
// Otherwise, figure out what restart method to use
var applicationDir = Path.GetDirectoryName(UpdateManager.Instance.ApplicationPath);
if ((File.Exists(_destinationFile) && !Utils.PermissionsCheck.HaveWritePermissionsForFileOrFolder(_destinationFile))
// If file don't exist and we don't have right to write.
// TODO: check directory from dirName to applicationDir one by one...
|| (!File.Exists(_destinationFile) && !Utils.PermissionsCheck.HaveWritePermissionsForFolder(applicationDir)))
{
return TaskExecutionStatus.RequiresPrivilegedAppRestart;
}
Expand Down