public VirtualFileSystem(VirtualFileSystemParams param) : base(param) { var rootDir = new VfsRamDirectory(this, "/", true); rootDir.AddLinkRef(); this.Root = rootDir; }
protected override async Task CreateDirectoryImplAsync(string directoryPath, FileFlags flags = FileFlags.None, CancellationToken cancel = default) { using (VfsPathParserContext ctx = await ParsePathInternalAsync(directoryPath, cancel)) { if (ctx.Exception == null) { if (ctx.LastEntity is VfsDirectory) { // Already exists return; } else { // There is existing another type object throw new VfsException(directoryPath, $"There are existing object at the speficied path."); } } if (ctx.Exception is VfsNotFoundException && ctx.RemainingPathElements.Count >= 1 && ctx.LastEntity is VfsDirectory) { var lastDir = (VfsDirectory)ctx.LastEntity; while (true) { if (ctx.RemainingPathElements.TryDequeue(out string?nextDirName) == false) { return; } nextDirName._MarkNotNull(); var newDirectory = new VfsRamDirectory(this, nextDirName); try { await lastDir.AddDirectoryAsync(newDirectory); } catch { await newDirectory.ReleaseLinkAsync(true); throw; } lastDir = newDirectory; } } else { throw ctx.Exception; } } }