You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@lucenenet.apache.org by "paulirwin (via GitHub)" <gi...@apache.org> on 2026/10/19 16:12:34 UTC
Re: [I] Fix issues with `FileSupport.GetCanonicalPath()` extension method [lucenenet]
paulirwin commented on issue #1409:
URL: https://github.com/apache/lucenenet/issues/1409#issuecomment-6271720377
@ajs-uk-dev Thanks for the analysis and volunteering to take this issue. I like your proposed approach and I'll assign it to you.
To answer your questions:
1. I'd say to leave `netstandard2.0` behavior as-is. We can always add that later based on user feedback as a non-breaking change if needed, but from our feedback, most `netstandard2.0` usage is to migrate off of .NET Framework, which is likely primarily Windows users anyways. If for some reason someone is moving a shared library from .NET Framework on Windows to modern .NET on Linux, I (personally) strongly recommend that people use multi-targeting rather than .NET Standard to do these migrations instead, in which case they would get the proper modern .NET build (i.e. `net10.0`). This would likely result in better performance, too.
2. Probably not fine as-is. Claude Code's analysis: The symlink-swap deployment pattern is common: `current -> index_v1`, build `index_v2`, atomically repoint `current`, reopen. With resolution cached forever under the unresolved key, `FSDirectory.Open("/data/current")` returns `index_v1` for the life of the process after the swap. That's a silent wrong-index bug. Prior art agrees: Harmony expired at 600s, the JDK's canon cache was 30s and then disabled by default (JDK-8198997) for exactly this reason. Call sites aren't hot (once per directory open, once per lock creation, GetLockID), so a few lstats per call is fine. Recommend: don't cache the link-resolved result at all on Unix (or drop the cache entirely). This conflicts with the GetOrAdd restructure item in the issue, so it's worth a design decision from @NightOwl888 before the PR lands. The unbounded growth of the cache is a pre-existing problem too (DirContentSource canonicalizes every file).
Some other smaller things from Claude Code's review:
- `ResolveLinkTarget(true)` itself throws `IOException` at 100 hops; the 40-hop loop cap should also catch that and take the same fallback.
- Fallback-to-unresolved on error silently loses lock dedup; keep the catch narrow (ELOOP / permission), and consider whether throwing like Java would be more honest.
- `path.FullName` collapses `..` lexically *before* link resolution, so `/a/link/../x` differs from `realpath` when `link` is a symlink. Java passes `..` intact to realpath. Edge case; acceptable, but should be noted in a comment.
- User-visible behavior change: `FSDirectory.Directory.FullName` and `ToString()` now return the resolved target on Unix. Faithful to Java (its `FSDirectory` ctor also canonicalizes), but worth a release-note line.
- Tests: `[LuceneNetSpecific]`, skipped on Windows (symlink creation needs privilege), covering link dir + nonexistent file, relative target, chained links, cycle, and the `IndexWriter` repro asserting `LockObtainFailedException`.
## Side observation (outside this PR's scope)
With `FileShare.Read` mapping to `LOCK_SH` on both sides, I'm not certain `Obtain()` conflicts *cross-process* on Linux either (only `IsLocked()` uses `FileShare.None`). The symlink fix doesn't touch that, and flock is inode-based so links don't matter there, but it may deserve its own look.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: dev-unsubscribe@lucenenet.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org