-
Notifications
You must be signed in to change notification settings - Fork 0
Phase 3: Fix review comments — exception narrowing, disposal safety, robust key migration #51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -21,15 +21,29 @@ public static IServiceCollection AddIntuneManagerCore(this IServiceCollection se | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // One-time migration: copy DataProtection key XML files from the legacy | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // location to the new one so existing encrypted profiles remain readable. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (Directory.Exists(legacyKeysPath) && !Directory.Exists(keysPath)) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var legacyKeyFiles = Directory.Exists(legacyKeysPath) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ? Directory.GetFiles(legacyKeysPath, "*.xml") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| : Array.Empty<string>(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var newKeyDirectoryHasKeys = Directory.Exists(keysPath) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| && Directory.GetFiles(keysPath, "*.xml").Length > 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+24
to
+29
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var legacyKeyFiles = Directory.Exists(legacyKeysPath) | |
| ? Directory.GetFiles(legacyKeysPath, "*.xml") | |
| : Array.Empty<string>(); | |
| var newKeyDirectoryHasKeys = Directory.Exists(keysPath) | |
| && Directory.GetFiles(keysPath, "*.xml").Length > 0; | |
| string[] legacyKeyFiles; | |
| if (Directory.Exists(legacyKeysPath)) | |
| { | |
| try | |
| { | |
| legacyKeyFiles = Directory.GetFiles(legacyKeysPath, "*.xml"); | |
| } | |
| catch | |
| { | |
| // Best-effort: if we cannot read legacy keys, treat as none found. | |
| legacyKeyFiles = Array.Empty<string>(); | |
| } | |
| } | |
| else | |
| { | |
| legacyKeyFiles = Array.Empty<string>(); | |
| } | |
| var newKeyDirectoryHasKeys = false; | |
| if (Directory.Exists(keysPath)) | |
| { | |
| try | |
| { | |
| newKeyDirectoryHasKeys = Directory.GetFiles(keysPath, "*.xml").Length > 0; | |
| } | |
| catch | |
| { | |
| // Best-effort: on failure, assume no existing keys so startup does not crash. | |
| newKeyDirectoryHasKeys = false; | |
| } | |
| } |
Copilot
AI
Feb 20, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The per-file copy is best-effort, but Directory.CreateDirectory(keysPath) is outside any try/catch now. If directory creation fails (permissions/disk), this will throw out of AddIntuneManagerCore; consider catching around the create+copy block to keep migration failures non-fatal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Directory.GetFiles(legacyKeysPath, "*.xml")can throw (e.g., access denied / IO errors). Since this migration code runs during DI setup, consider guarding this with a try/catch and treating failures as “no legacy keys found” so the app can still start and generate fresh keys if needed.