Пример #1
0
        /// <summary>
        /// The last arg is expected to be a remote path, if only one argument is
        /// given then the destination will be the remote user's directory
        /// </summary>
        /// <param name="args">is the list of arguments</param>
        /// <exception cref="Org.Apache.Hadoop.FS.PathIOException">if path doesn't exist or matches too many times
        ///     </exception>
        /// <exception cref="System.IO.IOException"/>
        protected internal virtual void GetRemoteDestination(List <string> args)
        {
            if (args.Count < 2)
            {
                dst = new PathData(Path.CurDir, GetConf());
            }
            else
            {
                string pathString = args.RemoveLast();
                // if the path is a glob, then it must match one and only one path
                PathData[] items = PathData.ExpandAsGlob(pathString, GetConf());
                switch (items.Length)
                {
                case 0:
                {
                    throw new PathNotFoundException(pathString);
                }

                case 1:
                {
                    dst = items[0];
                    break;
                }

                default:
                {
                    throw new PathIOException(pathString, "Too many matches");
                }
                }
            }
        }
Пример #2
0
 /// <summary>
 /// Expand the given argument into a list of
 /// <see cref="PathData"/>
 /// objects.
 /// The default behavior is to expand globs.  Commands may override to
 /// perform other expansions on an argument.
 /// </summary>
 /// <param name="arg">string pattern to expand</param>
 /// <returns>
 /// list of
 /// <see cref="PathData"/>
 /// objects
 /// </returns>
 /// <exception cref="System.IO.IOException">if anything goes wrong...</exception>
 protected internal virtual IList <PathData> ExpandArgument(string arg)
 {
     PathData[] items = PathData.ExpandAsGlob(arg, GetConf());
     if (items.Length == 0)
     {
         // it's a glob that failed to match
         throw new PathNotFoundException(arg);
     }
     return(Arrays.AsList(items));
 }
Пример #3
0
        /// <exception cref="System.Exception"/>
        public virtual void TestAbsoluteGlob()
        {
            PathData[] items = PathData.ExpandAsGlob(testDir + "/d1/f1*", conf);
            Assert.Equal(SortedString(testDir + "/d1/f1", testDir + "/d1/f1.1"
                                      ), SortedString(items));
            string absolutePathNoDriveLetter = testDir + "/d1/f1";

            if (Org.Apache.Hadoop.Util.Shell.Windows)
            {
                // testDir is an absolute path with a drive letter on Windows, i.e.
                // c:/some/path
                // and for the test we want something like the following
                // /some/path
                absolutePathNoDriveLetter = Runtime.Substring(absolutePathNoDriveLetter,
                                                              2);
            }
            items = PathData.ExpandAsGlob(absolutePathNoDriveLetter, conf);
            Assert.Equal(SortedString(absolutePathNoDriveLetter), SortedString
                             (items));
            items = PathData.ExpandAsGlob(".", conf);
            Assert.Equal(SortedString("."), SortedString(items));
        }
Пример #4
0
        /// <summary>For each source path, execute the command</summary>
        /// <returns>0 if it runs successfully; -1 if it fails</returns>
        public virtual int RunAll()
        {
            int exitCode = 0;

            foreach (string src in args)
            {
                try
                {
                    PathData[] srcs = PathData.ExpandAsGlob(src, GetConf());
                    foreach (PathData s in srcs)
                    {
                        Run(s.path);
                    }
                }
                catch (IOException e)
                {
                    exitCode = -1;
                    DisplayError(e);
                }
            }
            return(exitCode);
        }
Пример #5
0
 /// <exception cref="System.Exception"/>
 public virtual void TestRelativeGlobBack()
 {
     fs.SetWorkingDirectory(new Path("d1"));
     PathData[] items = PathData.ExpandAsGlob("../d2/*", conf);
     Assert.Equal(SortedString("../d2/f3"), SortedString(items));
 }
Пример #6
0
 /// <exception cref="System.Exception"/>
 public virtual void TestRelativeGlob()
 {
     PathData[] items = PathData.ExpandAsGlob("d1/f1*", conf);
     Assert.Equal(SortedString("d1/f1", "d1/f1.1"), SortedString(items
                                                                 ));
 }