Fix configs seed self-copy in all-users scope - #3543
Conversation
There was a problem hiding this comment.
PR Summary:
- Fixes a bug where
SeedConfigfails with a misleading file-lock error when source and target resolve to the same config file in all-users scope (ProgramData → same ProgramData file). - Normalizes source/target paths via
Path.GetFullPath, compares withOrdinalIgnoreCase, and skips the copy when they're identical — logging a debug message and returning success instead of throwing. - Preserves lock intent by applying read-only attributes on the target when
lockSeedConfigis true. - Extracts the lock logic into a shared
ApplySeedConfigLockhelper to avoid duplication. - Adds unit tests covering same-path skip, same-path with lock, and different-path copy behavior.
Review Summary:
The fix is well-targeted and correctly addresses issue #1266. The path normalization and same-path short-circuit logic is sound, and the refactoring into ApplySeedConfigLock is clean. One medium-severity issue: NormalizePath (which calls Path.GetFullPath) is invoked outside the try block that wraps failures in PyRevitException, so malformed paths will propagate unwrapped System.ArgumentException instead of the expected PyRevitException — this breaks the PR's stated goal of preserving exception-wrapping semantics. The fix is to move the samePath computation inside the existing try. One low-severity observation: the same-path branch silently skips the lock when the config file doesn't exist, with no diagnostic log explaining that the lock wasn't applied. Tests are well-structured with proper setup/cleanup and environment variable isolation.
Suggestions
- compute same-path check inside the try block so path resolution errors are wrapped in PyRevitException as before - log a debug message when lockSeedConfig is set but the config file is missing in the same-path case - update tests for upstream active-config resolution (admin-locked machine config now drives the same-path scenario)
|
Pulling the PR branch fast-forwarded in upstream develop changes that reworked active-config resolution (GetActiveConfig now routes non-elevated processes to the per-user config), which broke the two same-path tests. I updated pyRevitLabs.UnitTests.PyRevitConfigs.cs to drive the same-path scenario via an admin-locked (read-only) machine config, which resolves deterministically regardless of elevation. Validation: Build: 0 Warning(s) 0 Error(s) |
Fix configs seed self-copy failure in all-users scope
Description
Hey @jmcouffin - I came across this when updating our pyRevit wix based installer. Looking it up online, seems a few more users over the years have had this issue - although, perhaps this 'bug' is intended feature of pyrevit. Let me know eitherway!
This pull request attemps to fix a known bug where configs seed can fail with a misleading file-lock style error when source and target resolve to the same config file in all-users scope. This PR was generated using GPT5.3 Codex and Fable5 via Github Copilot on VSC.
What changed:
Background and prior reports:
configs-seed-error
cloning-pyrevit-and-our-extensions-for-deployment-with-powershell-doesnt-work
Checklist
Validation performed:
Result summary:
Related Issues
Additional Notes
Reference documentation:
Implementation note: