ContentProvider more async

This commit is contained in:
2023-08-24 15:50:11 +02:00
parent f1daca788e
commit ff1f6e1c3e
31 changed files with 136 additions and 69 deletions

View File

@@ -54,12 +54,13 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
});*/
}
public override bool CanHandlePath(NativePath path)
public override async Task<bool> CanHandlePathAsync(NativePath path)
{
var rootDrive = Items
.FirstOrDefault(r =>
var rootDrive = await Items
.ToAsyncEnumerable()
.FirstOrDefaultAwaitAsync(async r =>
path.Path.StartsWith(
GetNativePath(r.Path).Path,
(await GetNativePathAsync(r.Path)).Path,
_isCaseInsensitive
? StringComparison.InvariantCultureIgnoreCase
: StringComparison.InvariantCulture
@@ -73,8 +74,8 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
{
var rootDriveInfos = _rootDriveInfos.Value;
var rootDriveInfo = rootDriveInfos.FirstOrDefault(d => path.Path.StartsWith(d.Path.Path));
if(rootDriveInfo is null) return null;
if (rootDriveInfo is null) return null;
return new VolumeSizeInfo(rootDriveInfo.Size, rootDriveInfo.Free);
}
@@ -391,7 +392,10 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
nativePath.TrimStart(Constants.SeparatorChar).Split(Path.DirectorySeparatorChar)))
.TrimEnd(Constants.SeparatorChar))!;
public override NativePath GetNativePath(FullName fullName)
public override ValueTask<NativePath> GetNativePathAsync(FullName fullName)
=> ValueTask.FromResult(GetNativePath(fullName));
public NativePath GetNativePath(FullName fullName)
{
var path = string.Join(Path.DirectorySeparatorChar, fullName.Path.Split(Constants.SeparatorChar).Skip(1));
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && !path.StartsWith("/")) path = "/" + path;

View File

@@ -24,7 +24,7 @@ public class LocalItemCreator : ItemCreatorBase<ILocalContentProvider>
public override async Task CreateContainerAsync(ILocalContentProvider contentProvider, FullName fullName)
{
_logger.LogTrace("Start creating container {FullName}", fullName);
var path = contentProvider.GetNativePath(fullName).Path;
var path = (await contentProvider.GetNativePathAsync(fullName)).Path;
if (Directory.Exists(path))
{
_logger.LogTrace("Container with path {Path} already exists", path);
@@ -54,7 +54,7 @@ public class LocalItemCreator : ItemCreatorBase<ILocalContentProvider>
public override async Task CreateElementAsync(ILocalContentProvider contentProvider, FullName fullName)
{
_logger.LogTrace("Start creating element {FullName}", fullName);
var path = contentProvider.GetNativePath(fullName).Path;
var path = (await contentProvider.GetNativePathAsync(fullName)).Path;
if (File.Exists(path))
{
_logger.LogTrace("Element with path {Path} already exists", path);

View File

@@ -24,7 +24,7 @@ public class LocalItemDeleter : IItemDeleter<ILocalContentProvider>
public async Task DeleteAsync(ILocalContentProvider contentProvider, FullName fullName)
{
_logger.LogTrace("Start deleting item {FullName}", fullName);
var nativePath = contentProvider.GetNativePath(fullName).Path;
var nativePath = (await contentProvider.GetNativePathAsync(fullName)).Path;
try
{

View File

@@ -26,8 +26,8 @@ public class LocalItemMover : IItemMover<ILocalContentProvider>
_logger.LogTrace("Start renaming item {FullName}", fullName);
try
{
var source = contentProvider.GetNativePath(fullName);
var destination = contentProvider.GetNativePath(newPath);
var source = await contentProvider.GetNativePathAsync(fullName);
var destination = await contentProvider.GetNativePathAsync(newPath);
if (File.Exists(source.Path))
{