Skip to content

Remove empty directories after mod update file deletion#250

Merged
ManlyMarco merged 6 commits intomasterfrom
copilot/remove-empty-directories-on-update
Apr 10, 2026
Merged

Remove empty directories after mod update file deletion#250
ManlyMarco merged 6 commits intomasterfrom
copilot/remove-empty-directories-on-update

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 10, 2026

When mod updates remove files, their parent directories may be left behind as empty folders. This adds cleanup logic to walk up the directory tree and remove empty directories after each file deletion.

Changes

  • UpdateItem.Update(): In the delete-only path (RemoteFile == null), after the target file is removed, walks up TargetPath.Directory and deletes any empty directories until hitting a non-empty dir or the game root
    • Emptiness check and delete are in the same try block to handle concurrent filesystem modifications
    • Catches specific exceptions (IOException, UnauthorizedAccessException) — logs and breaks on failure
    • Stops at InstallDirectoryHelper.GameDirectory to avoid over-deletion

Copilot AI linked an issue Apr 10, 2026 that may be closed by this pull request
Copilot AI and others added 2 commits April 10, 2026 15:30
…pty dir cleanup

Agent-Logs-Url: https://github.com/IllusionMods/KKManager/sessions/55d8ec97-441e-4357-b271-bea6d6e85151

Co-authored-by: ManlyMarco <39247311+ManlyMarco@users.noreply.github.com>
Copilot AI changed the title [WIP] Remove empty directories during mod update Remove empty directories after mod update file deletion Apr 10, 2026
Copilot AI requested a review from ManlyMarco April 10, 2026 15:33
Copy link
Copy Markdown
Collaborator

@ManlyMarco ManlyMarco left a comment

Choose a reason for hiding this comment

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

@copilot Handle DirectoryNotFoundException and SecurityException as well

…dir cleanup

Agent-Logs-Url: https://github.com/IllusionMods/KKManager/sessions/cf293b54-a97e-489f-af9d-569067a4cf69

Co-authored-by: ManlyMarco <39247311+ManlyMarco@users.noreply.github.com>
Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 10, 2026

@copilot Handle DirectoryNotFoundException and SecurityException as well

Done in 6093bf1 — added DirectoryNotFoundException and SecurityException to the catch blocks.

Copilot AI requested a review from ManlyMarco April 10, 2026 15:40
Comment thread src/KKManager.Updater/Data/UpdateItem.cs Outdated
@ManlyMarco ManlyMarco marked this pull request as ready for review April 10, 2026 15:43
Copy link
Copy Markdown
Collaborator

@ManlyMarco ManlyMarco left a comment

Choose a reason for hiding this comment

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

@copilot Build error: D:\a\KKManager\KKManager\src\KKManager.Updater\Data\UpdateItem.cs(132,72): error CS1061: 'IEnumerable' does not contain a definition for 'Any' and no accessible extension method 'Any' accepting a first argument of type 'IEnumerable' could be found (are you missing a using directive or an assembly reference?) [D:\a\KKManager\KKManager\src\KKManager.Updater\KKManager.Updater.csproj]

Copy link
Copy Markdown
Contributor Author

Copilot AI commented Apr 10, 2026

@copilot Build error: D:\a\KKManager\KKManager\src\KKManager.Updater\Data\UpdateItem.cs(132,72): error CS1061: 'IEnumerable' does not contain a definition for 'Any' and no accessible...

Fixed in 27e56f3 — added using System.Linq; which was missing for the .Any() call.

Copilot AI requested a review from ManlyMarco April 10, 2026 15:49
@ManlyMarco ManlyMarco merged commit cc0950d into master Apr 10, 2026
2 checks passed
@ManlyMarco ManlyMarco deleted the copilot/remove-empty-directories-on-update branch April 10, 2026 15:59
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.

Remove empty directories during mod update

2 participants