diff --git a/src/DynamoCore/Utilities/LuceneSearchUtility.cs b/src/DynamoCore/Utilities/LuceneSearchUtility.cs index a4bb9b87220..d125eadb365 100644 --- a/src/DynamoCore/Utilities/LuceneSearchUtility.cs +++ b/src/DynamoCore/Utilities/LuceneSearchUtility.cs @@ -439,6 +439,8 @@ internal void AddNodeTypeToSearchIndex(NodeSearchElement node, Document doc) { CreateLuceneIndexWriter(OpenMode.CREATE_OR_APPEND); } + // If the index writer is still null, skip the indexing + if (writer == null) return; SetDocumentFieldValue(doc, nameof(LuceneConfig.NodeFieldsEnum.FullCategoryName), node.FullCategoryName); SetDocumentFieldValue(doc, nameof(LuceneConfig.NodeFieldsEnum.Name), node.Name); diff --git a/src/DynamoCoreWpf/ViewModels/PackageManager/PackageManagerClientViewModel.cs b/src/DynamoCoreWpf/ViewModels/PackageManager/PackageManagerClientViewModel.cs index aca34008833..3f21b7b36f8 100644 --- a/src/DynamoCoreWpf/ViewModels/PackageManager/PackageManagerClientViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/PackageManager/PackageManagerClientViewModel.cs @@ -1010,6 +1010,8 @@ internal virtual void InstallPackage(PackageDownloadHandle packageDownloadHandle } } SetPackageState(packageDownloadHandle, installPath); + // Dispose Index writer to avoid file lock + Search.LuceneSearch.LuceneUtilityNodeSearch.DisposeWriter(); Analytics.TrackEvent(Actions.Installed, Categories.PackageManagerOperations, $"{packageDownloadHandle?.Name}"); } catch (Exception e) diff --git a/src/DynamoCoreWpf/ViewModels/PackageManager/PackagePathViewModel.cs b/src/DynamoCoreWpf/ViewModels/PackageManager/PackagePathViewModel.cs index adbc2ff7d43..56ee6602601 100644 --- a/src/DynamoCoreWpf/ViewModels/PackageManager/PackagePathViewModel.cs +++ b/src/DynamoCoreWpf/ViewModels/PackageManager/PackagePathViewModel.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Collections.ObjectModel; using Dynamo.Core; @@ -266,6 +266,8 @@ private void CommitChanges(object param) packageLoader.LoadNewCustomNodesAndPackages(newPaths, customNodeManager); } packagePathsEnabled.Clear(); + // Dispose Index writer to avoid file lock + Search.LuceneSearch.LuceneUtilityNodeSearch.DisposeWriter(); } internal void SetPackagesScheduledState(string packagePath, bool packagePathDisabled) diff --git a/src/DynamoUtilities/PathHelper.cs b/src/DynamoUtilities/PathHelper.cs index f93f3453c4b..29c650602c0 100644 --- a/src/DynamoUtilities/PathHelper.cs +++ b/src/DynamoUtilities/PathHelper.cs @@ -37,6 +37,7 @@ public static Exception CreateFolderIfNotExist(string folderPath) { try { + if (string.IsNullOrEmpty(folderPath)) return null; // When network path is access denied, the Directory.Exits however still // return true. // EnumerateDirectories operation is additional check