diff options
author | Marius Ungureanu <marius.ungureanu@xamarin.com> | 2017-05-15 15:45:44 +0300 |
---|---|---|
committer | Marius Ungureanu <marius.ungureanu@xamarin.com> | 2017-05-15 15:45:44 +0300 |
commit | 6867993d0b2e8d3e9a52a217e1f4c028b26f6086 (patch) | |
tree | 74a355bc850415213cbca820ed33df92979c8f9b /Mono.Addins/Mono.Addins.Database | |
parent | 32d7c2ae3ae6edd2e2d6fe3987941626dff63008 (diff) |
[Scan] Fix cleanups and properly handle new mono.cecil behaviour.
Diffstat (limited to 'Mono.Addins/Mono.Addins.Database')
-rw-r--r-- | Mono.Addins/Mono.Addins.Database/AddinDatabase.cs | 102 | ||||
-rw-r--r-- | Mono.Addins/Mono.Addins.Database/AddinFileSystemExtension.cs | 6 | ||||
-rw-r--r-- | Mono.Addins/Mono.Addins.Database/AddinScanner.cs | 9 |
3 files changed, 64 insertions, 53 deletions
diff --git a/Mono.Addins/Mono.Addins.Database/AddinDatabase.cs b/Mono.Addins/Mono.Addins.Database/AddinDatabase.cs index bdaa33f..ebd15d1 100644 --- a/Mono.Addins/Mono.Addins.Database/AddinDatabase.cs +++ b/Mono.Addins/Mono.Addins.Database/AddinDatabase.cs @@ -1323,60 +1323,63 @@ namespace Mono.Addins.Database } AddinScanner scanner = new AddinScanner (this, scanResult, monitor); - - // Check if any of the previously scanned folders has been deleted - - foreach (string file in Directory.GetFiles (AddinFolderCachePath, "*.data")) { - AddinScanFolderInfo folderInfo; - bool res = ReadFolderInfo (monitor, file, out folderInfo); - bool validForDomain = scanResult.Domain == null || folderInfo.Domain == GlobalDomain || folderInfo.Domain == scanResult.Domain; - if (!res || (validForDomain && !fs.DirectoryExists (folderInfo.Folder))) { - if (res) { - // Folder has been deleted. Remove the add-ins it had. - scanner.UpdateDeletedAddins (monitor, folderInfo, scanResult); - } - else { - // Folder info file corrupt. Regenerate all. - scanResult.ChangesFound = true; - scanResult.RegenerateRelationData = true; + try { + + // Check if any of the previously scanned folders has been deleted + + foreach (string file in Directory.GetFiles (AddinFolderCachePath, "*.data")) { + AddinScanFolderInfo folderInfo; + bool res = ReadFolderInfo (monitor, file, out folderInfo); + bool validForDomain = scanResult.Domain == null || folderInfo.Domain == GlobalDomain || folderInfo.Domain == scanResult.Domain; + if (!res || (validForDomain && !fs.DirectoryExists (folderInfo.Folder))) { + if (res) { + // Folder has been deleted. Remove the add-ins it had. + scanner.UpdateDeletedAddins (monitor, folderInfo, scanResult); + } else { + // Folder info file corrupt. Regenerate all. + scanResult.ChangesFound = true; + scanResult.RegenerateRelationData = true; + } + + if (!scanResult.CheckOnly) + SafeDelete (monitor, file); + else if (scanResult.ChangesFound) + return; } - - if (!scanResult.CheckOnly) - SafeDelete (monitor, file); - else if (scanResult.ChangesFound) - return; } - } - - // Look for changes in the add-in folders - - if (registry.StartupDirectory != null) - scanner.ScanFolder (monitor, registry.StartupDirectory, null, scanResult); - - if (scanResult.CheckOnly && (scanResult.ChangesFound || monitor.IsCanceled)) - return; - - if (scanResult.Domain == null) - scanner.ScanFolder (monitor, HostsPath, GlobalDomain, scanResult); - - if (scanResult.CheckOnly && (scanResult.ChangesFound || monitor.IsCanceled)) - return; - - foreach (string dir in registry.GlobalAddinDirectories) { + + // Look for changes in the add-in folders + + if (registry.StartupDirectory != null) + scanner.ScanFolder (monitor, registry.StartupDirectory, null, scanResult); + if (scanResult.CheckOnly && (scanResult.ChangesFound || monitor.IsCanceled)) return; - scanner.ScanFolderRec (monitor, dir, GlobalDomain, scanResult); - } - - if (scanResult.CheckOnly || !scanResult.ChangesFound) - return; - - // Scan the files which have been modified - - currentScanResult = scanResult; - foreach (FileToScan file in scanResult.FilesToScan) - scanner.ScanFile (monitor, file.File, file.AddinScanFolderInfo, scanResult); + if (scanResult.Domain == null) + scanner.ScanFolder (monitor, HostsPath, GlobalDomain, scanResult); + + if (scanResult.CheckOnly && (scanResult.ChangesFound || monitor.IsCanceled)) + return; + + foreach (string dir in registry.GlobalAddinDirectories) { + if (scanResult.CheckOnly && (scanResult.ChangesFound || monitor.IsCanceled)) + return; + scanner.ScanFolderRec (monitor, dir, GlobalDomain, scanResult); + } + + if (scanResult.CheckOnly || !scanResult.ChangesFound) + return; + + // Scan the files which have been modified + + currentScanResult = scanResult; + + foreach (FileToScan file in scanResult.FilesToScan) + scanner.ScanFile (monitor, file.File, file.AddinScanFolderInfo, scanResult); + } finally { + scanner.CleanupReflector (); + } // Save folder info @@ -1461,6 +1464,7 @@ namespace Mono.Addins.Database } } finally { + scanner.CleanupReflector (); AppDomain.CurrentDomain.AssemblyResolve -= resolver; if (einfo != null) einfo.RemoveEventHandler (AppDomain.CurrentDomain, resolver); } diff --git a/Mono.Addins/Mono.Addins.Database/AddinFileSystemExtension.cs b/Mono.Addins/Mono.Addins.Database/AddinFileSystemExtension.cs index 0606cd1..9b9de68 100644 --- a/Mono.Addins/Mono.Addins.Database/AddinFileSystemExtension.cs +++ b/Mono.Addins/Mono.Addins.Database/AddinFileSystemExtension.cs @@ -190,6 +190,12 @@ namespace Mono.Addins.Database reflector.Initialize (locator); return reflector; } + + internal void CleanupReflector() + { + if (reflector is IDisposable disposable) + disposable.Dispose (); + } /// <summary> /// Gets a value indicating whether this <see cref="Mono.Addins.Database.AddinFileSystemExtension"/> needs to be isolated from the main execution process diff --git a/Mono.Addins/Mono.Addins.Database/AddinScanner.cs b/Mono.Addins/Mono.Addins.Database/AddinScanner.cs index f8029bb..44cacd8 100644 --- a/Mono.Addins/Mono.Addins.Database/AddinScanner.cs +++ b/Mono.Addins/Mono.Addins.Database/AddinScanner.cs @@ -524,8 +524,6 @@ namespace Mono.Addins.Database // Something went wrong while scanning the assembly. We'll ignore it for now. monitor.ReportError ("There was an error while scanning add-in: " + filePath, ex); return false; - } finally { - (reflector as IDisposable)?.Dispose (); } } @@ -582,8 +580,6 @@ namespace Mono.Addins.Database // Something went wrong while scanning the assembly. We'll ignore it for now. monitor.ReportError ("There was an error while scanning assembly: " + filePath, ex); return false; - } finally { - (reflector as IDisposable)?.Dispose (); } } @@ -1276,5 +1272,10 @@ namespace Mono.Addins.Database { return "/" + Addin.GetIdName (desc.AddinId) + "/TypeExtensions/" + typeFullName; } + + internal void CleanupReflector() + { + fs.CleanupReflector (); + } } } |