Fix crash with empty fullname path

This commit is contained in:
2023-02-22 22:13:38 +01:00
parent 28bc479ee4
commit 3dccaa5243
8 changed files with 46 additions and 37 deletions

View File

@@ -76,11 +76,11 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
{
if ((path?.Length ?? 0) == 0)
{
return Task.FromResult((IItem) this);
return Task.FromResult((IItem)this);
}
else if (Directory.Exists(path))
{
return Task.FromResult((IItem) DirectoryToContainer(
return Task.FromResult((IItem)DirectoryToContainer(
new DirectoryInfo(path!.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar),
pointInTime,
!itemInitializationSettings.SkipChildInitialization)
@@ -88,7 +88,7 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
}
else if (File.Exists(path))
{
return Task.FromResult((IItem) FileToElement(new FileInfo(path), pointInTime));
return Task.FromResult((IItem)FileToElement(new FileInfo(path), pointInTime));
}
var type = forceResolvePathType switch
@@ -120,10 +120,10 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
return forceResolvePathType switch
{
AbsolutePathType.Container => Task.FromResult(
(IItem) CreateEmptyContainer(
(IItem)CreateEmptyContainer(
nativePath,
pointInTime,
Observable.Return(new List<Exception>() {innerException})
Observable.Return(new List<Exception>() { innerException })
)
),
AbsolutePathType.Element => Task.FromResult(CreateEmptyElement(nativePath)),
@@ -142,11 +142,14 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
var fullName = GetFullName(nativePath);
var parentFullName = fullName.GetParent();
var parent = new AbsolutePath(
_timelessContentProvider,
pointInTime,
parentFullName ?? new FullName(""),
AbsolutePathType.Container);
var parent =
parentFullName is null
? null
: new AbsolutePath(
_timelessContentProvider,
pointInTime,
parentFullName,
AbsolutePathType.Container);
return new Container(
name,
@@ -208,11 +211,14 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
{
var fullName = GetFullName(directoryInfo.FullName);
var parentFullName = fullName.GetParent();
var parent = new AbsolutePath(
_timelessContentProvider,
pointInTime,
parentFullName ?? new FullName(""),
AbsolutePathType.Container);
var parent =
parentFullName is null
? null
: new AbsolutePath(
_timelessContentProvider,
pointInTime,
parentFullName,
AbsolutePathType.Container);
var exceptions = new BehaviorSubject<IEnumerable<Exception>>(Enumerable.Empty<Exception>());
return new Container(
@@ -247,14 +253,14 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
var items = GetItemsByContainer(directoryInfo, pointInTime);
var result = new SourceCache<AbsolutePath, string>(i => i.Path.Path);
if (items.Count == 0) return (IObservable<IChangeSet<AbsolutePath, string>>?) result.Connect().StartWithEmpty();
if (items.Count == 0) return (IObservable<IChangeSet<AbsolutePath, string>>?)result.Connect().StartWithEmpty();
result.AddOrUpdate(items);
return (IObservable<IChangeSet<AbsolutePath, string>>?) result.Connect();
return (IObservable<IChangeSet<AbsolutePath, string>>?)result.Connect();
}
catch (Exception e)
{
exceptions.OnNext(new List<Exception> {e});
exceptions.OnNext(new List<Exception> { e });
}
return null;
@@ -299,10 +305,10 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
private FullName GetFullName(NativePath nativePath) => GetFullName(nativePath.Path);
private FullName GetFullName(string nativePath) =>
new((Name + Constants.SeparatorChar +
FullName.CreateSafe((Name + Constants.SeparatorChar +
string.Join(Constants.SeparatorChar,
nativePath.TrimStart(Constants.SeparatorChar).Split(Path.DirectorySeparatorChar)))
.TrimEnd(Constants.SeparatorChar));
.TrimEnd(Constants.SeparatorChar))!;
public override NativePath GetNativePath(FullName fullName)
{
@@ -328,7 +334,7 @@ public sealed partial class LocalContentProvider : ContentProviderBase, ILocalCo
var size = maxLength ?? realFileSize switch
{
> int.MaxValue => int.MaxValue,
_ => (int) realFileSize
_ => (int)realFileSize
};
var buffer = new byte[size];
await reader.ReadAsync(buffer.AsMemory(0, size), cancellationToken);