public static bool AllowedToAccess(this Path chjailedRootPath, string otherDirectory) { var other = new Path(otherDirectory); // if the given non-root is empty, we are looking at a relative path if (String.IsNullOrEmpty(other.Info.Root)) return true; // they must be on the same drive. if (!String.IsNullOrEmpty(chjailedRootPath.Info.DriveLetter) && other.Info.DriveLetter != chjailedRootPath.Info.DriveLetter) return false; // we do not allow access to directories outside of the specified directory. return other.Info.IsParentOf(chjailedRootPath.Info); }
static IEnumerable<string> GetFilterPaths(string filter) { var lastWasSubFolder = false; var path = new Path(filter); foreach (var segment in path.Segments) { if (segment == Subfolder) if (!lastWasSubFolder) lastWasSubFolder = true; else continue; else lastWasSubFolder = false; yield return segment; } }