Skip to content

Commit bc3e104

Browse files
committed
overwrite
1 parent 94ed31b commit bc3e104

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

src/Sentry.Unity.Editor/Android/AndroidManifestConfiguration.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,22 @@ internal void CopyAndroidSdkToGradleProject(string unityProjectPath, string grad
228228
throw new DirectoryNotFoundException($"Failed to find the Android SDK at '{androidSdkPath}'.");
229229
}
230230

231+
Directory.CreateDirectory(targetPath);
232+
231233
_logger.LogInfo("Copying the Android SDK to '{0}'.", gradlePath);
232234
foreach (var file in Directory.GetFiles(androidSdkPath))
233235
{
234236
var destinationFile = Path.Combine(targetPath, Path.GetFileName(file));
235-
if (!File.Exists(destinationFile))
237+
238+
try
239+
{
240+
File.Copy(file, destinationFile, overwrite: true);
241+
_logger.LogDebug("Copied SDK file: {0}", Path.GetFileName(file));
242+
}
243+
catch (Exception e)
236244
{
237-
File.Copy(file, destinationFile);
245+
_logger.LogError(e, "Failed to copy SDK file: {0}", Path.GetFileName(file));
246+
throw;
238247
}
239248
}
240249
}

test/Sentry.Unity.Editor.Tests/Android/AndroidManifestConfigurationTests.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,28 @@ public void CopyAndroidSdkToGradleProject_AndroidNativeSupportDisabledButSdkAlre
421421
Directory.Delete(fakeProjectPath, true);
422422
}
423423

424+
[Test]
425+
public void CopyAndroidSdkToGradleProject_SdkAlreadyExists_OverwritesExistingSdk()
426+
{
427+
var fakeProjectPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
428+
var unityProjectPath = Path.Combine(fakeProjectPath, "UnityProject");
429+
var gradleProjectPath = Path.Combine(fakeProjectPath, "GradleProject");
430+
DebugSymbolUploadTests.SetupFakeProject(fakeProjectPath);
431+
432+
var targetPath = Path.Combine(gradleProjectPath, "unityLibrary", "libs");
433+
Directory.CreateDirectory(targetPath);
434+
var existingFile = Path.Combine(targetPath, "androidSdk.jar");
435+
File.WriteAllText(existingFile, "original content");
436+
437+
var sut = _fixture.GetSut();
438+
sut.CopyAndroidSdkToGradleProject(unityProjectPath, gradleProjectPath);
439+
440+
var newContent = File.ReadAllBytes(existingFile);
441+
Assert.AreNotEqual("original content", System.Text.Encoding.UTF8.GetString(newContent));
442+
443+
Directory.Delete(fakeProjectPath, true);
444+
}
445+
424446
private string WithAndroidManifest(Action<string> callback)
425447
{
426448
var basePath = GetFakeManifestFileBasePath();

0 commit comments

Comments
 (0)