mono/mono-addins

RunPendingUninstalls not cleaning up empty directories

Opened this issue · 0 comments

In situations where addins are frequently added, removed, and updated, the addins directory tends to fill up with empty directories between application restarts rather quickly. Each one of these directories is then scanned on Registry.Update, potentially causing slowdowns once a lot of them exist.

Perhaps AddinDatabase.RunPendingUninstalls can try deleting the containing folder the addin file being removed was stored in, keeping things a lot more tidy for end users, and avoiding a massive directory of empty folders.

Something as simple as:

if (canUninstall) {
	foreach (string file in adn.Files.OrderByDescending(s => s).ToList()) {
		var dir = Path.GetDirectoryName(file);
		if (dir != null) {
			try {
				Directory.Delete(dir);
			}
			catch {
			}
		}
	}
	Configuration.UnregisterForUninstall (adn.AddinId);
	changesDone = true;
}

to replace the previous code of:

if (canUninstall) {
	Configuration.UnregisterForUninstall (adn.AddinId);
	changesDone = true;
}

Seems to do the trick, but I'm not sure if that code is compatible with all the targets of Mono.Addins, so just throwing out an example.

I'm not familiar with the possible directory structure for multi-assembly addins, but in my simple testing I just had a single file in a directory so it worked as intended. Maybe a recursive delete can be done regardless if the directory is empty or not, but I'm not sure of the implications of that, or if that's even desirable. I can't think of any case where empty directories of uninstalled addins are desirable though!