Skip to content

Commit

Permalink
Avoid accessing not existed files in second stage updater (#615)
Browse files Browse the repository at this point in the history
  • Loading branch information
SadPencil authored Jan 3, 2025
1 parent 89ea5a1 commit b4e0589
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions SecondStageUpdater/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace SecondStageUpdater;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading;

using Rampastring.Tools;

internal sealed class Program
Expand Down Expand Up @@ -143,17 +144,20 @@ private static void Main(string[] args)
try
{
FileInfo copiedFile = SafePath.GetFile(baseDirectory.FullName, relativeFileName);
bool isReadOnly = copiedFile.IsReadOnly;

Write($"Updating {relativeFileName}");

if (isReadOnly)
// If the file is read-only, we need to remove the read-only attribute before copying it
if (copiedFile.Exists && copiedFile.IsReadOnly)
{
copiedFile.IsReadOnly = false;

fileInfo.CopyTo(copiedFile.FullName, true);

if (isReadOnly)
fileInfo.CopyTo(copiedFile.FullName, true);
copiedFile.IsReadOnly = true;
}
else
{
fileInfo.CopyTo(copiedFile.FullName, true);
}
}
catch (Exception ex)
{
Expand Down

0 comments on commit b4e0589

Please sign in to comment.