Hopefully fix UnixPath.Path being null

This commit is contained in:
Mike Nolan 2024-07-22 19:11:13 -05:00
parent 1f3f1c9b89
commit 1818aa12dc
3 changed files with 14 additions and 28 deletions

View File

@ -843,7 +843,6 @@ namespace Tesses.VirtualFilesystem
public UnixPath()
{
_path = "/";
_parts = new string[0];
}
public UnixPath(IEnumerable<string> pathParts)
@ -854,7 +853,7 @@ namespace Tesses.VirtualFilesystem
path /= new UnixPath(item);
}
_parts = path._parts;
path = path._path;
}
public UnixPath(UnixPath path1, UnixPath path2)
{
@ -862,25 +861,12 @@ namespace Tesses.VirtualFilesystem
List<string> pathParts = new List<string>();
pathParts.AddRange(path1.Parts);
pathParts.AddRange(path2.Parts);
SetPath(pathParts);
}
private void SetPath(IEnumerable<string> p)
{
_parts = p.ToArray();
StringBuilder pa = new StringBuilder();
for (int i = 0; i < _parts.Length; i++)
{
pa.Append($"/{_parts[i]}");
}
if(pa.Length > 0)
_path = pa.ToString();
else
_path = "/";
_parts = pathParts.ToArray();
}
public UnixPath(UnixPath path1)
{
_parts = path1._parts.ToArray();
_path = path1._path;
}
public UnixPath(params string[] pathParts) : this((IEnumerable<string>)pathParts)
@ -897,7 +883,7 @@ namespace Tesses.VirtualFilesystem
public UnixPath(string path)
{
SetPath(path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries));
_parts=path.Split(new char[] { '/' }, StringSplitOptions.RemoveEmptyEntries);
}
@ -946,8 +932,8 @@ namespace Tesses.VirtualFilesystem
p.Add(path2._parts[i]);
}
var path = new UnixPath();
path.SetPath(p);
var path = new UnixPath(p.ToArray());
return path;
}
public static implicit operator UnixPath(string path)
@ -971,9 +957,9 @@ namespace Tesses.VirtualFilesystem
return true;
}
internal string _path;
public string Path { get { return _path; } }
public string Path =>$"/{string.Join("/",_parts)}";
public string Name { get { if (_parts.Length == 0) return ""; return _parts[_parts.Length - 1]; } set{
if(_parts.Length > 0) _parts[_parts.Length-1] = value;
@ -1000,7 +986,7 @@ namespace Tesses.VirtualFilesystem
var p = new UnixPath();
if (!ParentIsRoot)
{
p.SetPath(_parts.Take(_parts.Length - 1));
p._parts=_parts.Take(_parts.Length - 1).ToArray();
}
return p;
}
@ -1014,7 +1000,7 @@ namespace Tesses.VirtualFilesystem
public override string ToString()
{
return _path;
return Path;
}
}

View File

@ -17,9 +17,9 @@
<PackageId>Tesses.VirtualFilesystem.Base</PackageId>
<Author>Mike Nolan</Author>
<Company>Tesses</Company>
<Version>1.0.1</Version>
<AssemblyVersion>1.0.1</AssemblyVersion>
<FileVersion>1.0.1</FileVersion>
<Version>1.0.2</Version>
<AssemblyVersion>1.0.2</AssemblyVersion>
<FileVersion>1.0.2</FileVersion>
<Description>Another VirtualFilesystem for .NET</Description>
<PackageLicenseExpression>GPL-3.0-only</PackageLicenseExpression>
<PackageRequireLicenseAcceptance>true</PackageRequireLicenseAcceptance>

View File

@ -45,7 +45,7 @@ namespace Tesses.VirtualFilesystem.Filesystems
}
public UnixPath ConvertUPathToUnixPath(UPath path)
{
return new UnixPath(path.ToString());
return new UnixPath(path.FullName);
}
public override void CreateDirectory(UnixPath directory)
{