コード例 #1
0
        /// <exception cref="URISyntaxException"/>
        /// <exception cref="System.IO.IOException"/>
        /// <exception cref="Org.Apache.Hadoop.FS.FileAlreadyExistsException"/>
        /// <exception cref="Org.Apache.Hadoop.FS.UnsupportedFileSystemException"/>
        private void CreateLink(string src, string target, bool isLinkMerge, UserGroupInformation
                                aUgi)
        {
            // Validate that src is valid absolute path
            Path srcPath = new Path(src);

            if (!srcPath.IsAbsoluteAndSchemeAuthorityNull())
            {
                throw new IOException("ViewFs:Non absolute mount name in config:" + src);
            }
            string[] srcPaths = BreakIntoPathComponents(src);
            InodeTree.INodeDir <T> curInode = root;
            int i;

            // Ignore first initial slash, process all except last component
            for (i = 1; i < srcPaths.Length - 1; i++)
            {
                string iPath = srcPaths[i];
                InodeTree.INode <T> nextInode = curInode.ResolveInternal(iPath);
                if (nextInode == null)
                {
                    InodeTree.INodeDir <T> newDir = curInode.AddDir(iPath, aUgi);
                    newDir.InodeDirFs = GetTargetFileSystem(newDir);
                    nextInode         = newDir;
                }
                if (nextInode is InodeTree.INodeLink)
                {
                    // Error - expected a dir but got a link
                    throw new FileAlreadyExistsException("Path " + nextInode.fullPath + " already exists as link"
                                                         );
                }
                else
                {
                    System.Diagnostics.Debug.Assert((nextInode is InodeTree.INodeDir));
                    curInode = (InodeTree.INodeDir <T>)nextInode;
                }
            }
            // Now process the last component
            // Add the link in 2 cases: does not exist or a link exists
            string iPath_1 = srcPaths[i];

            // last component
            if (curInode.ResolveInternal(iPath_1) != null)
            {
                //  directory/link already exists
                StringBuilder strB = new StringBuilder(srcPaths[0]);
                for (int j = 1; j <= i; ++j)
                {
                    strB.Append('/').Append(srcPaths[j]);
                }
                throw new FileAlreadyExistsException("Path " + strB + " already exists as dir; cannot create link here"
                                                     );
            }
            InodeTree.INodeLink <T> newLink;
            string fullPath = curInode.fullPath + (curInode == root ? string.Empty : "/") + iPath_1;

            if (isLinkMerge)
            {
                // Target is list of URIs
                string[] targetsList    = StringUtils.GetStrings(target);
                URI[]    targetsListURI = new URI[targetsList.Length];
                int      k = 0;
                foreach (string itarget in targetsList)
                {
                    targetsListURI[k++] = new URI(itarget);
                }
                newLink = new InodeTree.INodeLink <T>(fullPath, aUgi, GetTargetFileSystem(targetsListURI
                                                                                          ), targetsListURI);
            }
            else
            {
                newLink = new InodeTree.INodeLink <T>(fullPath, aUgi, GetTargetFileSystem(new URI(
                                                                                              target)), new URI(target));
            }
            curInode.AddLink(iPath_1, newLink);
            mountPoints.AddItem(new InodeTree.MountPoint <T>(src, newLink));
        }