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

Commit 1ccda46

Browse files
Merge pull request #935 from github-for-unity/copymethod-changes
CopyMethod changes
2 parents fddbd32 + 7562f7d commit 1ccda46

File tree

5 files changed

+60
-9
lines changed

5 files changed

+60
-9
lines changed

src/GitHub.Api/GitHub.Api.45.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
<Compile Include="Application\ApplicationManagerBase.cs" />
9494
<Compile Include="Helpers\Constants.cs" />
9595
<Compile Include="Helpers\Validation.cs" />
96+
<Compile Include="Installer\CopyHelper.cs" />
9697
<Compile Include="Installer\GitInstaller.cs" />
9798
<Compile Include="Installer\OctorunInstaller.cs" />
9899
<Compile Include="Installer\UnzipTask.cs" />

src/GitHub.Api/GitHub.Api.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@
104104
<Compile Include="Application\ApplicationManagerBase.cs" />
105105
<Compile Include="Helpers\Constants.cs" />
106106
<Compile Include="Helpers\Validation.cs" />
107+
<Compile Include="Installer\CopyHelper.cs" />
107108
<Compile Include="Installer\GitInstaller.cs" />
108109
<Compile Include="Installer\OctorunInstaller.cs" />
109110
<Compile Include="Installer\UnzipTask.cs" />
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using GitHub.Logging;
6+
7+
namespace GitHub.Unity
8+
{
9+
public static class CopyHelper
10+
{
11+
private static readonly ILogging Logger = LogHelper.GetLogger(typeof(CopyHelper));
12+
13+
public static void Copy(NPath fromPath, NPath toPath)
14+
{
15+
try
16+
{
17+
18+
CopyFolder(fromPath, toPath);
19+
}
20+
catch (Exception ex1)
21+
{
22+
Logger.Warning(ex1, "Error copying from " + fromPath + " to " + toPath + ". Attempting to copy contents.");
23+
24+
try
25+
{
26+
CopyFolderContents(fromPath, toPath);
27+
}
28+
catch (Exception ex2)
29+
{
30+
Logger.Error(ex2, "Error copying from " + fromPath + " to " + toPath + ".");
31+
throw;
32+
}
33+
}
34+
finally
35+
{
36+
fromPath.DeleteIfExists();
37+
}
38+
}
39+
public static void CopyFolder(NPath fromPath, NPath toPath)
40+
{
41+
Logger.Trace("CopyFolder fromPath: {0} toPath:{1}", fromPath.ToString(), toPath.ToString());
42+
43+
toPath.EnsureParentDirectoryExists();
44+
fromPath.Move(toPath);
45+
}
46+
47+
public static void CopyFolderContents(NPath fromPath, NPath toPath)
48+
{
49+
Logger.Trace("CopyFolderContents fromPath: {0} toPath:{1}", fromPath.ToString(), toPath.ToString());
50+
51+
toPath.DeleteContents();
52+
fromPath.MoveFiles(toPath, true);
53+
}
54+
}
55+
}

src/GitHub.Api/Installer/GitInstaller.cs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -307,9 +307,7 @@ private GitInstallationState ExtractGit(GitInstallationState state)
307307
{
308308
Logger.Trace("Moving Git source:{0} target:{1}", source.ToString(), target.ToString());
309309

310-
target.DeleteContents();
311-
source.MoveFiles(target, true);
312-
source.Parent.Delete();
310+
CopyHelper.Copy(source, target);
313311

314312
state.GitIsValid = true;
315313

@@ -335,9 +333,7 @@ private GitInstallationState ExtractGit(GitInstallationState state)
335333
{
336334
Logger.Trace("Moving GitLFS source:{0} target:{1}", source.ToString(), target.ToString());
337335

338-
target.DeleteContents();
339-
source.MoveFiles(target, true);
340-
source.Parent.Delete();
336+
CopyHelper.Copy(source, target);
341337

342338
state.GitLfsIsValid = true;
343339
}

src/GitHub.Api/Installer/OctorunInstaller.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ private NPath MoveOctorun(NPath fromPath)
5555

5656
Logger.Trace("MoveOctorun fromPath: {0} toPath:{1}", fromPath.ToString(), toPath.ToString());
5757

58-
toPath.DeleteContents();
59-
fromPath.MoveFiles(toPath, true);
60-
fromPath.Parent.Delete();
58+
CopyHelper.Copy(fromPath, toPath);
6159

6260
return installDetails.ExecutablePath;
6361
}

0 commit comments

Comments
 (0)