Skip to content

Commit 9171a38

Browse files
committed
Use CopyIfChanged
1 parent d18ba56 commit 9171a38

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/Xamarin.Android.Build.Tasks/Tasks/GenerateJavaStubs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ void Run (DirectoryAssemblyResolver res)
217217

218218
#if ENABLE_MARSHAL_METHODS
219219
if (!Debug) {
220-
var rewriter = new MarshalMethodsAssemblyRewriter (classifier.MarshalMethods, classifier.Assemblies, marshalMethodsAssemblyPaths);
220+
var rewriter = new MarshalMethodsAssemblyRewriter (classifier.MarshalMethods, classifier.Assemblies, marshalMethodsAssemblyPaths, Log);
221221
rewriter.Rewrite (res);
222222
}
223223
#endif

src/Xamarin.Android.Build.Tasks/Utilities/MarshalMethodsAssemblyRewriter.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
using System.IO;
55

66
using Java.Interop.Tools.Cecil;
7+
using Microsoft.Android.Build.Tasks;
8+
using Microsoft.Build.Utilities;
79
using Mono.Cecil;
10+
using Xamarin.Android.Tools;
811

912
namespace Xamarin.Android.Tasks
1013
{
@@ -13,12 +16,14 @@ class MarshalMethodsAssemblyRewriter
1316
IDictionary<string, IList<MarshalMethodEntry>> methods;
1417
ICollection<AssemblyDefinition> uniqueAssemblies;
1518
IDictionary <string, HashSet<string>> assemblyPaths;
19+
TaskLoggingHelper log;
1620

17-
public MarshalMethodsAssemblyRewriter (IDictionary<string, IList<MarshalMethodEntry>> methods, ICollection<AssemblyDefinition> uniqueAssemblies, IDictionary <string, HashSet<string>> assemblyPaths)
21+
public MarshalMethodsAssemblyRewriter (IDictionary<string, IList<MarshalMethodEntry>> methods, ICollection<AssemblyDefinition> uniqueAssemblies, IDictionary <string, HashSet<string>> assemblyPaths, TaskLoggingHelper log)
1822
{
1923
this.methods = methods ?? throw new ArgumentNullException (nameof (methods));
2024
this.uniqueAssemblies = uniqueAssemblies ?? throw new ArgumentNullException (nameof (uniqueAssemblies));
2125
this.assemblyPaths = assemblyPaths ?? throw new ArgumentNullException (nameof (assemblyPaths));
26+
this.log = log ?? throw new ArgumentNullException (nameof (log));
2227
}
2328

2429
public void Rewrite (DirectoryAssemblyResolver resolver)
@@ -87,11 +92,12 @@ public void Rewrite (DirectoryAssemblyResolver resolver)
8792
void MoveFile (string source, string target)
8893
{
8994
Console.WriteLine ($"Moving '{source}' => '{target}'");
90-
if (File.Exists (target)) {
91-
File.Delete (target);
95+
Files.CopyIfChanged (source, target);
96+
try {
97+
File.Delete (source);
98+
} catch (Exception ex) {
99+
log.LogWarning ($"Unable to delete source file '{source}' when moving it to '{target}'");
92100
}
93-
94-
File.Move (source, target);
95101
}
96102
}
97103

0 commit comments

Comments
 (0)