diff --git a/src/GitHub.Api/GitHub.Api.45.csproj b/src/GitHub.Api/GitHub.Api.45.csproj index 05a9c6b23..480e35974 100644 --- a/src/GitHub.Api/GitHub.Api.45.csproj +++ b/src/GitHub.Api/GitHub.Api.45.csproj @@ -93,6 +93,7 @@ + diff --git a/src/GitHub.Api/GitHub.Api.csproj b/src/GitHub.Api/GitHub.Api.csproj index f52c319da..bf916ed46 100644 --- a/src/GitHub.Api/GitHub.Api.csproj +++ b/src/GitHub.Api/GitHub.Api.csproj @@ -104,6 +104,7 @@ + diff --git a/src/GitHub.Api/Installer/CopyHelper.cs b/src/GitHub.Api/Installer/CopyHelper.cs new file mode 100644 index 000000000..22ec43579 --- /dev/null +++ b/src/GitHub.Api/Installer/CopyHelper.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using GitHub.Logging; + +namespace GitHub.Unity +{ + public static class CopyHelper + { + private static readonly ILogging Logger = LogHelper.GetLogger(typeof(CopyHelper)); + + public static void Copy(NPath fromPath, NPath toPath) + { + try + { + + CopyFolder(fromPath, toPath); + } + catch (Exception ex1) + { + Logger.Warning(ex1, "Error copying from " + fromPath + " to " + toPath + ". Attempting to copy contents."); + + try + { + CopyFolderContents(fromPath, toPath); + } + catch (Exception ex2) + { + Logger.Error(ex2, "Error copying from " + fromPath + " to " + toPath + "."); + throw; + } + } + finally + { + fromPath.DeleteIfExists(); + } + } + public static void CopyFolder(NPath fromPath, NPath toPath) + { + Logger.Trace("CopyFolder fromPath: {0} toPath:{1}", fromPath.ToString(), toPath.ToString()); + + toPath.EnsureParentDirectoryExists(); + fromPath.Move(toPath); + } + + public static void CopyFolderContents(NPath fromPath, NPath toPath) + { + Logger.Trace("CopyFolderContents fromPath: {0} toPath:{1}", fromPath.ToString(), toPath.ToString()); + + toPath.DeleteContents(); + fromPath.MoveFiles(toPath, true); + } + } +} diff --git a/src/GitHub.Api/Installer/GitInstaller.cs b/src/GitHub.Api/Installer/GitInstaller.cs index 71dd77361..67b502a94 100644 --- a/src/GitHub.Api/Installer/GitInstaller.cs +++ b/src/GitHub.Api/Installer/GitInstaller.cs @@ -307,9 +307,7 @@ private GitInstallationState ExtractGit(GitInstallationState state) { Logger.Trace("Moving Git source:{0} target:{1}", source.ToString(), target.ToString()); - target.DeleteContents(); - source.MoveFiles(target, true); - source.Parent.Delete(); + CopyHelper.Copy(source, target); state.GitIsValid = true; @@ -335,9 +333,7 @@ private GitInstallationState ExtractGit(GitInstallationState state) { Logger.Trace("Moving GitLFS source:{0} target:{1}", source.ToString(), target.ToString()); - target.DeleteContents(); - source.MoveFiles(target, true); - source.Parent.Delete(); + CopyHelper.Copy(source, target); state.GitLfsIsValid = true; } diff --git a/src/GitHub.Api/Installer/OctorunInstaller.cs b/src/GitHub.Api/Installer/OctorunInstaller.cs index 354bf69f3..0aa655d93 100644 --- a/src/GitHub.Api/Installer/OctorunInstaller.cs +++ b/src/GitHub.Api/Installer/OctorunInstaller.cs @@ -55,9 +55,7 @@ private NPath MoveOctorun(NPath fromPath) Logger.Trace("MoveOctorun fromPath: {0} toPath:{1}", fromPath.ToString(), toPath.ToString()); - toPath.DeleteContents(); - fromPath.MoveFiles(toPath, true); - fromPath.Parent.Delete(); + CopyHelper.Copy(fromPath, toPath); return installDetails.ExecutablePath; }