From af198237ca6b213b77d8bdb535bd37b18a683aef Mon Sep 17 00:00:00 2001 From: Tim Etchells Date: Mon, 22 Feb 2021 23:38:15 -0500 Subject: [PATCH] Delete script files before replacing during update (#984) * Delete script files before replacing during update Signed-off-by: Tim Etchells * Use IOUtil.DelteFile() Co-authored-by: Tingluo Huang --- src/Runner.Listener/SelfUpdater.cs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/Runner.Listener/SelfUpdater.cs b/src/Runner.Listener/SelfUpdater.cs index 18e8cb870..92ed0ce73 100644 --- a/src/Runner.Listener/SelfUpdater.cs +++ b/src/Runner.Listener/SelfUpdater.cs @@ -225,7 +225,7 @@ namespace GitHub.Runner.Listener using (FileStream fs = new FileStream(archiveFile, FileMode.Create, FileAccess.Write, FileShare.None, bufferSize: 4096, useAsync: true)) using (Stream result = await httpClient.GetStreamAsync(_targetPackage.DownloadUrl)) { - //81920 is the default used by System.IO.Stream.CopyTo and is under the large object heap threshold (85k). + //81920 is the default used by System.IO.Stream.CopyTo and is under the large object heap threshold (85k). await result.CopyToAsync(fs, 81920, downloadCts.Token); await fs.FlushAsync(downloadCts.Token); } @@ -357,8 +357,13 @@ namespace GitHub.Runner.Listener Trace.Info($"Copy any remaining .sh/.cmd files into runner root."); foreach (FileInfo file in new DirectoryInfo(latestRunnerDirectory).GetFiles() ?? new FileInfo[0]) { - // Copy and replace the file. - file.CopyTo(Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Root), file.Name), true); + string destination = Path.Combine(HostContext.GetDirectory(WellKnownDirectory.Root), file.Name); + + // Removing the file instead of just trying to overwrite it works around permissions issues on linux. + // https://github.com/actions/runner/issues/981 + Trace.Info($"Copy {file.FullName} to {destination}"); + IOUtil.DeleteFile(destination); + file.CopyTo(destination, true); } }