Skip to content

[#14] Address Copilot review follow-ups#124

Draft
SkowronskiAndrew wants to merge 1 commit into
mainfrom
issue14-followup
Draft

[#14] Address Copilot review follow-ups#124
SkowronskiAndrew wants to merge 1 commit into
mainfrom
issue14-followup

Conversation

@SkowronskiAndrew

Copy link
Copy Markdown
Collaborator

Summary

Follow-up to #122 (merged), addressing the Copilot review comments that arrived after merge. All changes are small robustness/accuracy improvements to the UTF-8 path marshalling work; no behavior change for normal use.

Changes

  • CreateArchive: marshal only the first count entries of sourceFiles/aliases (what the native call actually consumes) instead of every array element, and validate count against the array lengths up front. Previously a count larger than the arrays could make native read past the marshalled data.
  • GetArchiveNode comment: clarify that the "only ASCII round-trips" limitation on the StringBuilder outputs is Windows-specific — on macOS/Linux the Ansi marshalling is UTF-8. (These are Unity-controlled internal names that stay ASCII, so still not an issue in practice.)
  • NonAsciiPath.WithCopy (test helper): best-effort temp-directory cleanup so a Directory.Delete failure (e.g. a handle not yet released on Windows) can't mask a real test failure thrown from the test body.

Testing

  • dotnet test UnityFileSystem.Tests — non-ASCII path tests green (10/10 across versions); full build clean.

- CreateArchive: marshal only the first `count` entries (matching what native
  consumes) and validate `count` against the array lengths, instead of
  marshalling every element.
- Clarify that the StringBuilder-output ASCII limitation is Windows-specific
  (Ansi marshals as UTF-8 on macOS/Linux).
- NonAsciiPath.WithCopy: best-effort temp-dir cleanup so a delete failure can't
  mask a test failure.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Follow-up robustness and accuracy tweaks to the UTF-8 path marshalling work in the UnityFileSystem native interop layer and its non-ASCII-path test helpers.

Changes:

  • Tightens CreateArchive marshalling to allocate/marshal only the first count entries and validates count against input array lengths.
  • Clarifies platform behavior in the StringBuilder return-value marshalling comment.
  • Makes non-ASCII-path test temp-directory cleanup best-effort to avoid masking failures from the test body.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
UnityFileSystem/DllWrapper.cs Adds count bounds validation and marshals only the consumed subset of string arrays; updates marshalling behavior comment.
UnityFileSystem.Tests/UnityFileSystemTests.cs Wraps temp-directory deletion in a best-effort cleanup path for non-ASCII tests.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 198 to +202
// Strings returned from native (here and in the other StringBuilder-based calls) come back as
// UTF-8 bytes but are marshalled as the system ANSI code page, so only ASCII round-trips correctly.
// These are internal archive/serialized-file names, which Unity keeps ASCII, so it's not an issue in
// practice. Input paths, by contrast, are marshalled as UTF-8 (LPUTF8Str) to support non-ASCII paths.
// UTF-8 bytes but are marshalled as the system ANSI code page. On Windows that's a lossy code page,
// so only ASCII round-trips correctly (on macOS/Linux it happens to be UTF-8). These are internal
// archive/serialized-file names, which Unity keeps ASCII, so it's not an issue in practice. Input
// paths, by contrast, are marshalled as UTF-8 (LPUTF8Str) to support non-ASCII paths on all platforms.
Comment on lines +30 to +33
// Best-effort cleanup: a delete failure (e.g. a handle not yet released on Windows)
// must not mask a test failure thrown from the block above.
try { Directory.Delete(dir, true); }
catch { /* ignore */ }
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.

2 participants