Skip to content

fix: cleanup stale native sdk during build - #2793

Closed
bitsandfoxes wants to merge 2 commits into
mainfrom
fix/macos-backend-cleanup
Closed

fix: cleanup stale native sdk during build#2793
bitsandfoxes wants to merge 2 commits into
mainfrom
fix/macos-backend-cleanup

Conversation

@bitsandfoxes

Copy link
Copy Markdown
Contributor

Fixes an issue when switching native backend from cocoa to native or the other way around.

Comment on lines +269 to 273
{
logger.LogDebug("Removing stale Sentry artifact from prior build: '{0}'", staleDsym);
Directory.Delete(staleDsym, recursive: true);
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: The cleanup logic for Sentry.dylib.dSYM fails because it checks for a directory with Directory.Exists(), but the artifact is actually a file.
Severity: MEDIUM

Suggested Fix

Update the cleanup logic to handle both files and directories. First, check if a directory exists at the path with Directory.Exists() and delete it recursively if it does. Then, add a check using File.Exists() and use File.Delete() if a file is found at the same path. This ensures both stale directories and files are properly removed.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: src/Sentry.Unity.Editor/Native/BuildPostProcess.cs#L269-L273

Potential issue: The cleanup logic for stale build artifacts incorrectly assumes that
`Sentry.dylib.dSYM` is a directory. The build script actually creates this artifact as a
single file. The code uses `Directory.Exists()` to check for its presence, which returns
`false` for a file. As a result, when switching macOS backends between builds, the stale
`Sentry.dylib.dSYM` file from a previous build is not removed, which could lead to build
failures or resolution issues.

Did we get this right? 👍 / 👎 to inform future reviews.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 35f83af. Configure here.

{
logger.LogDebug("Removing stale Sentry artifact from prior build: '{0}'", staleDsym);
Directory.Delete(staleDsym, recursive: true);
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale dSYM treated as directory

Medium Severity

CleanupStaleMacOSArtifacts removes Sentry.dylib.dSYM only when Directory.Exists is true, but the Cocoa backend stores that artifact as a file (the DWARF binary copied by build-cocoa-sdk.ps1). GetNativePluginArtifact then copies that file into Contents/MacOS, so after switching backends the stale dSYM is never deleted. The new test creates a directory and therefore misses this failure mode.

Additional Locations (1)
Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 35f83af. Configure here.

@bitsandfoxes

Copy link
Copy Markdown
Contributor Author

got gaslit..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant