IKVM11  11
Java SE 11 Virtual Machine for .NET
Loading...
Searching...
No Matches
VfsMount.cs
Go to the documentation of this file.
1/*
2 Copyright (C) 2007-2011 Jeroen Frijters
3
4 This software is provided 'as-is', without any express or implied
5 warranty. In no event will the authors be held liable for any damages
6 arising from the use of this software.
7
8 Permission is granted to anyone to use this software for any purpose,
9 including commercial applications, and to alter it and redistribute it
10 freely, subject to the following restrictions:
11
12 1. The origin of this software must not be misrepresented; you must not
13 claim that you wrote the original software. If you use this software
14 in a product, an acknowledgment in the product documentation would be
15 appreciated but is not required.
16 2. Altered source versions must be plainly marked as such, and must not be
17 misrepresented as being the original software.
18 3. This notice may not be removed or altered from any source distribution.
19
20 Jeroen Frijters
21 jeroen@frijters.net
22
23*/
24using System;
25
27
28namespace IKVM.Runtime.Vfs
29{
30
34 internal partial class VfsMount
35 {
36
37 readonly string path;
38 readonly VfsEntry item;
39
45 public VfsMount(string path, VfsEntry item)
46 {
47 if (path is null)
48 throw new ArgumentNullException(nameof(path));
49 if (item is null)
50 throw new ArgumentNullException(nameof(item));
51
52 this.path = item is VfsDirectory ? PathExtensions.EnsureEndingDirectorySeparator(path) : path.TrimEnd(System.IO.Path.DirectorySeparatorChar);
53 this.item = item;
54 }
55
59 public string Path => path;
60
64 public VfsEntry Item => item;
65
71 public bool IsPath(string path) => path.StartsWith(this.path, StringComparison.Ordinal);
72
79 public VfsEntry GetEntry(string path)
80 {
81 if (path is null)
82 throw new ArgumentNullException(nameof(path));
83
84 var p = path.Split(PathExtensions.DirectorySeparatorChars, StringSplitOptions.RemoveEmptyEntries);
85 var c = Item;
86 for (int i = 0; i < p.Length; i++)
87 {
88 // can only recurse into directory
89 if (c is VfsDirectory directory)
90 {
91 // obtain next entry, but if null, simply return early
92 if ((c = directory.GetEntry(p[i])) == null)
93 return null;
94 }
95 else
96 {
97 return null;
98 }
99 }
100
101 // we're left with the last element
102 return c;
103 }
104
105 }
106
107}
Various extension methods for working with paths.
static string EnsureEndingDirectorySeparator(string path)
Ensures the given path ends with a directory separator.
static readonly char[] DirectorySeparatorChars