提交 a149a9a0 编写于 作者: C Cyrus Najmabadi

NRT

上级 a04d1d80
......@@ -27,8 +27,8 @@ internal abstract partial class AbstractPersistentStorageService : IChecksummedP
/// This lock guards all mutable fields in this type.
/// </summary>
private readonly object _lock = new object();
private ReferenceCountedDisposable<IChecksummedPersistentStorage> _currentPersistentStorage;
private SolutionId _currentPersistentStorageSolutionId;
private ReferenceCountedDisposable<IChecksummedPersistentStorage>? _currentPersistentStorage;
private SolutionId? _currentPersistentStorageSolutionId;
protected AbstractPersistentStorageService(IPersistentStorageLocationService locationService)
=> _locationService = locationService;
......@@ -71,7 +71,7 @@ internal IChecksummedPersistentStorage GetStorageWorker(Solution solution)
{
// We do, great. Increment our ref count for our caller. They'll decrement it
// when done with it.
return PersistentStorageReferenceCountedDisposableWrapper.AddReferenceCountToAndCreateWrapper(_currentPersistentStorage);
return PersistentStorageReferenceCountedDisposableWrapper.AddReferenceCountToAndCreateWrapper(_currentPersistentStorage!);
}
var workingFolder = _locationService.TryGetStorageLocation(solution);
......@@ -144,7 +144,7 @@ private IChecksummedPersistentStorage CreatePersistentStorage(Solution solution,
var databaseFilePath = GetDatabaseFilePath(workingFolderPath);
try
{
return TryOpenDatabase(solution, workingFolderPath, databaseFilePath)
return TryOpenDatabase(solution, workingFolderPath, databaseFilePath);
}
catch (Exception ex)
{
......@@ -164,7 +164,7 @@ private IChecksummedPersistentStorage CreatePersistentStorage(Solution solution,
private void Shutdown()
{
ReferenceCountedDisposable<IChecksummedPersistentStorage> storage = null;
ReferenceCountedDisposable<IChecksummedPersistentStorage>? storage = null;
lock (_lock)
{
......@@ -211,7 +211,9 @@ private PersistentStorageReferenceCountedDisposableWrapper(ReferenceCountedDispo
public static IChecksummedPersistentStorage AddReferenceCountToAndCreateWrapper(ReferenceCountedDisposable<IChecksummedPersistentStorage> storage)
{
return new PersistentStorageReferenceCountedDisposableWrapper(storage.TryAddReference());
// This should only be called from a caller that has a non-null storage that it
// already has a reference on. So .TryAddReference cannot fail.
return new PersistentStorageReferenceCountedDisposableWrapper(storage.TryAddReference() ?? throw new InvalidOperationException());
}
public void Dispose()
......
......@@ -32,9 +32,7 @@ public IWorkspaceService CreateService(HostWorkspaceServices workspaceServices)
case StorageDatabase.SQLite:
var locationService = workspaceServices.GetService<IPersistentStorageLocationService>();
if (locationService != null)
{
return new SQLitePersistentStorageService(optionService, locationService);
}
return new SQLitePersistentStorageService(locationService);
break;
}
......
......@@ -2,11 +2,12 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
#nullable enable
using System;
using System.IO;
using System.Runtime.InteropServices;
using Microsoft.CodeAnalysis.Host;
using Microsoft.CodeAnalysis.Options;
using Microsoft.CodeAnalysis.Shared.Utilities;
using Microsoft.CodeAnalysis.Storage;
using Roslyn.Utilities;
......@@ -19,7 +20,7 @@ internal partial class SQLitePersistentStorageService : AbstractPersistentStorag
private const string StorageExtension = "sqlite3";
private const string PersistentStorageFileName = "storage.ide";
private readonly IPersistentStorageFaultInjector _faultInjectorOpt;
private readonly IPersistentStorageFaultInjector? _faultInjectorOpt;
[DllImport("kernel32.dll")]
private static extern IntPtr LoadLibrary(string dllToLoad);
......@@ -41,6 +42,8 @@ private static bool TryInitializeLibrariesLazy()
{
var myFolder = Path.GetDirectoryName(
typeof(SQLitePersistentStorage).Assembly.Location);
if (myFolder == null)
return false;
var is64 = IntPtr.Size == 8;
var subfolder = is64 ? "x64" : "x86";
......@@ -68,10 +71,9 @@ public SQLitePersistentStorageService(IPersistentStorageLocationService location
}
public SQLitePersistentStorageService(
IOptionService optionService,
IPersistentStorageLocationService locationService,
IPersistentStorageFaultInjector faultInjector)
: this(optionService, locationService)
: this(locationService)
{
_faultInjectorOpt = faultInjector;
}
......@@ -98,7 +100,7 @@ protected override string GetDatabaseFilePath(string workingFolderPath)
return null;
}
SQLitePersistentStorage sqlStorage = null;
SQLitePersistentStorage? sqlStorage = null;
try
{
sqlStorage = new SQLitePersistentStorage(
......@@ -125,15 +127,19 @@ protected override string GetDatabaseFilePath(string workingFolderPath)
}
}
private static IDisposable TryGetDatabaseOwnership(string databaseFilePath)
private static IDisposable? TryGetDatabaseOwnership(string databaseFilePath)
{
return IOUtilities.PerformIO<IDisposable>(() =>
return IOUtilities.PerformIO<IDisposable?>(() =>
{
// make sure directory exist first.
EnsureDirectory(databaseFilePath);
var directoryName = Path.GetDirectoryName(databaseFilePath);
if (directoryName == null)
return null;
return File.Open(
Path.Combine(Path.GetDirectoryName(databaseFilePath), LockFile),
Path.Combine(directoryName, LockFile),
FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None);
});
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册