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

CopyMethod changes #935

Merged
merged 2 commits into from
Oct 10, 2018
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions src/GitHub.Api/GitHub.Api.45.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
<Compile Include="Application\ApplicationManagerBase.cs" />
<Compile Include="Helpers\Constants.cs" />
<Compile Include="Helpers\Validation.cs" />
<Compile Include="Installer\CopyHelper.cs" />
<Compile Include="Installer\GitInstaller.cs" />
<Compile Include="Installer\OctorunInstaller.cs" />
<Compile Include="Installer\UnzipTask.cs" />
Expand Down
1 change: 1 addition & 0 deletions src/GitHub.Api/GitHub.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@
<Compile Include="Application\ApplicationManagerBase.cs" />
<Compile Include="Helpers\Constants.cs" />
<Compile Include="Helpers\Validation.cs" />
<Compile Include="Installer\CopyHelper.cs" />
<Compile Include="Installer\GitInstaller.cs" />
<Compile Include="Installer\OctorunInstaller.cs" />
<Compile Include="Installer\UnzipTask.cs" />
Expand Down
55 changes: 55 additions & 0 deletions src/GitHub.Api/Installer/CopyHelper.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
8 changes: 2 additions & 6 deletions src/GitHub.Api/Installer/GitInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
Expand Down
4 changes: 1 addition & 3 deletions src/GitHub.Api/Installer/OctorunInstaller.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down