From ff725f931d9ccc87a7038f54bbd0697b16156ec8 Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Sat, 6 May 2017 23:10:40 -0700 Subject: [PATCH] tst: memfs-dotnet: testing --- tst/memfs-dotnet/Program.cs | 64 +++++++++++++++++++------------------ 1 file changed, 33 insertions(+), 31 deletions(-) diff --git a/tst/memfs-dotnet/Program.cs b/tst/memfs-dotnet/Program.cs index f9f125da..79f98202 100644 --- a/tst/memfs-dotnet/Program.cs +++ b/tst/memfs-dotnet/Program.cs @@ -79,18 +79,21 @@ namespace memfs } public FileNode Get(String FileName) { - return Map[FileName]; + FileNode FileNode; + return Map.TryGetValue(FileName, out FileNode) ? FileNode : null; } public FileNode GetMain(String FileName) { int Index = FileName.IndexOf(':'); if (0 > Index) return null; - return Map[FileName.Substring(0, Index)]; + FileNode FileNode; + return Map.TryGetValue(FileName.Substring(0, Index), out FileNode) ? FileNode : null; } public FileNode GetParent(String FileName, out Int32 Result) { - FileNode FileNode = Map[Path.GetDirectoryName(FileName)]; + FileNode FileNode; + Map.TryGetValue(Path.GetDirectoryName(FileName), out FileNode); if (null == FileNode) { Result = FileSystemBase.STATUS_OBJECT_PATH_NOT_FOUND; @@ -132,48 +135,47 @@ namespace memfs } public Boolean HasChild(FileNode FileNode) { - String MinName = FileNode.FileName + "\\"; - String MaxName = FileNode.FileName + "]"; - SortedSet View = Set.GetViewBetween(MinName, MaxName); - foreach (String Name in View) - if (Name.StartsWith(MinName, CaseInsensitive ? - StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal)) - return true; + foreach (String Name in GetChildrenFileNames(FileNode)) + return true; return false; } public IEnumerable GetChildrenFileNames(FileNode FileNode) { - String MinName = FileNode.FileName + "\\"; - String MaxName = FileNode.FileName + "]"; - SortedSet View = Set.GetViewBetween(MinName, MaxName); - foreach (String Name in View) - if (Name.StartsWith(MinName, CaseInsensitive ? - StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal)) + String MinName = "\\"; + String MaxName = "]"; + if ("\\" != FileNode.FileName) + { + MinName = FileNode.FileName + "\\"; + MaxName = FileNode.FileName + "]"; + } + foreach (String Name in Set.GetViewBetween(MinName, MaxName)) + if (Name.Length > MinName.Length && + -1 == Name.IndexOfAny(Delimiters, MinName.Length)) yield return Name; } public IEnumerable GetStreamFileNames(FileNode FileNode) { String MinName = FileNode.FileName + ":"; String MaxName = FileNode.FileName + ";"; - SortedSet View = Set.GetViewBetween(MinName, MaxName); - foreach (String Name in View) - if (Name.StartsWith(MinName, CaseInsensitive ? - StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal)) + foreach (String Name in Set.GetViewBetween(MinName, MaxName)) + if (Name.Length > MinName.Length) yield return Name; } public IEnumerable GetDescendantFileNames(FileNode FileNode) { - String MinName = FileNode.FileName; - String MaxName = FileNode.FileName + "]"; - SortedSet View = Set.GetViewBetween(MinName, MaxName); - foreach (String Name in View) - if (Name.StartsWith(MinName, CaseInsensitive ? - StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal) && - Name.Length == MinName.Length || (1 == MinName.Length && '\\' == MinName[0]) || - '\\' == Name[MinName.Length] || ':' == Name[MinName.Length]) + String MinName = "\\"; + String MaxName = "]"; + if ("\\" != FileNode.FileName) + { + MinName = FileNode.FileName; + MaxName = FileNode.FileName + "]"; + } + foreach (String Name in Set.GetViewBetween(MinName, MaxName)) + if (Name == MinName || Name.Length > MinName.Length) yield return Name; } + private static readonly Char[] Delimiters = new Char[] { '\\', ':' }; public Boolean CaseInsensitive; private SortedSet Set; private Dictionary Map; @@ -1078,8 +1080,8 @@ namespace memfs MountPoint = Host.MountPoint(); _Host = Host; - Log(EVENTLOG_INFORMATION_TYPE, String.Format("{0} -t {1} -n {2} -s {3} {4}{5}{6}{7}{8}{9}", - PROGNAME, FileInfoTimeout, MaxFileNodes, MaxFileSize, + Log(EVENTLOG_INFORMATION_TYPE, String.Format("{0} -t {1} -n {2} -s {3}{4}{5}{6}{7}{8}{9}", + PROGNAME, (Int32)FileInfoTimeout, MaxFileNodes, MaxFileSize, null != RootSddl ? " -S " : "", null != RootSddl ? RootSddl : "", null != VolumePrefix && 0 < VolumePrefix.Length ? " -u " : "", null != VolumePrefix && 0 < VolumePrefix.Length ? VolumePrefix : "", @@ -1101,7 +1103,7 @@ namespace memfs " -F FileSystemName\n" + " -S RootSddl [file rights: FA, etc; NO generic rights: GA, etc.]\n" + " -u \\Server\\Share [UNC prefix (single backslash)]\n" + - " -m MountPoint [X:|*|directory]\n", + " -m MountPoint [X:|* (required if no UNC prefix)]\n", ex.HasMessage ? ex.Message + "\n" : "", PROGNAME)); throw;