public void Mount(string path, IDatabase db)
        {
            lock (mounts)
            {
                ManagedNode node;
                if (path == PathHelper.Slash)
                {
                    node = root;
                }
                else
                {
                    path = path.Trim('/');
                    node = root.FindOrCreate(0, path.Split('/'));
                    if (node == null)
                    {
                        throw new MountException("Could not mount on path " + path
                                                 + " because it is invalid.");
                    }
                }

                if (node.IsMountPoint)
                {
                    throw new MountException("Could not mount on path " + path
                                             + " because there is already a mount point.");
                }
                node.SetAsMountNode(db.Root);
                mounts.Add(path, db);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Finds the node and if it does not exist, it creates it.
        /// </summary>
        /// <param name="path">The path.</param>
        /// <returns>Managed node at path (constructed).</returns>
        internal ManagedNode FindOrCreate(int i, string[] path)
        {
            // We resolved the whole path.
            if (path.Length == i)
            {
                return(this);
            }

            lock (SyncRoot)
            {
                AssertNotDisposed();
                ManagedNode redirect = common.GetChild(node, path[i]);

                // We must create transparent node.
                if (redirect == null)
                {
                    redirect = common.CreateTransparent(path[i]);
                }

                // We remove processed string.
                return(redirect.FindOrCreate(i + 1, path));
            }
        }