コード例 #1
0
    public VirtualFileSystem(VirtualFileSystemParams param) : base(param)
    {
        var rootDir = new VfsRamDirectory(this, "/", true);

        rootDir.AddLinkRef();

        this.Root = rootDir;
    }
コード例 #2
0
    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;
            }
        }
    }