From 1818aa12dcb07a48e600a8fdae016decd2c1e4b1 Mon Sep 17 00:00:00 2001 From: Mike Nolan Date: Mon, 22 Jul 2024 19:11:13 -0500 Subject: [PATCH] Hopefully fix UnixPath.Path being null --- Tesses.VirtualFilesystem.Base/Class1.cs | 34 ++++++------------- .../Tesses.VirtualFilesystem.Base.csproj | 6 ++-- Tesses.VirtualFilesystem.Zio/Class1.cs | 2 +- 3 files changed, 14 insertions(+), 28 deletions(-) diff --git a/Tesses.VirtualFilesystem.Base/Class1.cs b/Tesses.VirtualFilesystem.Base/Class1.cs index 89efaec..f01de56 100644 --- a/Tesses.VirtualFilesystem.Base/Class1.cs +++ b/Tesses.VirtualFilesystem.Base/Class1.cs @@ -843,7 +843,6 @@ namespace Tesses.VirtualFilesystem public UnixPath() { - _path = "/"; _parts = new string[0]; } public UnixPath(IEnumerable 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 pathParts = new List(); pathParts.AddRange(path1.Parts); pathParts.AddRange(path2.Parts); - SetPath(pathParts); - } - private void SetPath(IEnumerable 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)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; } } diff --git a/Tesses.VirtualFilesystem.Base/Tesses.VirtualFilesystem.Base.csproj b/Tesses.VirtualFilesystem.Base/Tesses.VirtualFilesystem.Base.csproj index 1d21863..809709d 100644 --- a/Tesses.VirtualFilesystem.Base/Tesses.VirtualFilesystem.Base.csproj +++ b/Tesses.VirtualFilesystem.Base/Tesses.VirtualFilesystem.Base.csproj @@ -17,9 +17,9 @@ Tesses.VirtualFilesystem.Base Mike Nolan Tesses - 1.0.1 - 1.0.1 - 1.0.1 + 1.0.2 + 1.0.2 + 1.0.2 Another VirtualFilesystem for .NET GPL-3.0-only true diff --git a/Tesses.VirtualFilesystem.Zio/Class1.cs b/Tesses.VirtualFilesystem.Zio/Class1.cs index 0e027ff..04c0aa0 100644 --- a/Tesses.VirtualFilesystem.Zio/Class1.cs +++ b/Tesses.VirtualFilesystem.Zio/Class1.cs @@ -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) {