From 594dd9eb259220f6e18acfd939f1b95fbdb04c37 Mon Sep 17 00:00:00 2001 From: Robert Joseph Evans Date: Wed, 4 Apr 2012 15:28:17 +0000 Subject: [PATCH] MAPREDUCE-3082. Archive command take wrong path for input file with current directory (John George via bobby) git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1309453 13f79535-47bb-0310-9956-ffa450edef68 --- hadoop-mapreduce-project/CHANGES.txt | 3 ++ .../apache/hadoop/tools/HadoopArchives.java | 7 ++++ .../hadoop/tools/TestHadoopArchives.java | 42 ++++++++++++++++++- 3 files changed, 50 insertions(+), 2 deletions(-) diff --git a/hadoop-mapreduce-project/CHANGES.txt b/hadoop-mapreduce-project/CHANGES.txt index b84f64b5bf..e407a2276e 100644 --- a/hadoop-mapreduce-project/CHANGES.txt +++ b/hadoop-mapreduce-project/CHANGES.txt @@ -248,6 +248,9 @@ Release 0.23.3 - UNRELEASED MAPREDUCE-3682 Tracker URL says AM tasks run on localhost. (Ravi Prakash via tgraves) + MAPREDUCE-3082. Archive command take wrong path for input file with current + directory (John George via bobby) + Release 0.23.2 - UNRELEASED INCOMPATIBLE CHANGES diff --git a/hadoop-tools/hadoop-archives/src/main/java/org/apache/hadoop/tools/HadoopArchives.java b/hadoop-tools/hadoop-archives/src/main/java/org/apache/hadoop/tools/HadoopArchives.java index cbe8b9cbab..3ff94ac0f8 100644 --- a/hadoop-tools/hadoop-archives/src/main/java/org/apache/hadoop/tools/HadoopArchives.java +++ b/hadoop-tools/hadoop-archives/src/main/java/org/apache/hadoop/tools/HadoopArchives.java @@ -830,11 +830,18 @@ public int run(String[] args) throws Exception { throw new IOException("Parent path not specified."); } parentPath = new Path(args[i+1]); + if (!parentPath.isAbsolute()) { + parentPath= parentPath.getFileSystem(getConf()).makeQualified(parentPath); + } + i+=2; //read the rest of the paths for (; i < args.length; i++) { if (i == (args.length - 1)) { destPath = new Path(args[i]); + if (!destPath.isAbsolute()) { + destPath = destPath.getFileSystem(getConf()).makeQualified(destPath); + } } else { Path argPath = new Path(args[i]); diff --git a/hadoop-tools/hadoop-archives/src/test/java/org/apache/hadoop/tools/TestHadoopArchives.java b/hadoop-tools/hadoop-archives/src/test/java/org/apache/hadoop/tools/TestHadoopArchives.java index a00be5701a..a06b0b9ad3 100644 --- a/hadoop-tools/hadoop-archives/src/test/java/org/apache/hadoop/tools/TestHadoopArchives.java +++ b/hadoop-tools/hadoop-archives/src/test/java/org/apache/hadoop/tools/TestHadoopArchives.java @@ -103,7 +103,42 @@ protected void tearDown() throws Exception { super.tearDown(); } - + + public void testRelativePath() throws Exception { + fs.delete(archivePath, true); + + final Path sub1 = new Path(inputPath, "dir1"); + fs.mkdirs(sub1); + createFile(sub1, "a", fs); + final Configuration conf = mapred.createJobConf(); + final FsShell shell = new FsShell(conf); + + final List originalPaths = lsr(shell, "input"); + System.out.println("originalPath: " + originalPaths); + final URI uri = fs.getUri(); + final String prefix = "har://hdfs-" + uri.getHost() +":" + uri.getPort() + + archivePath.toUri().getPath() + Path.SEPARATOR; + + { + final String harName = "foo.har"; + final String[] args = { + "-archiveName", + harName, + "-p", + "input", + "*", + "archive" + }; + System.setProperty(HadoopArchives.TEST_HADOOP_ARCHIVES_JAR_PATH, HADOOP_ARCHIVES_JAR); + final HadoopArchives har = new HadoopArchives(mapred.createJobConf()); + assertEquals(0, ToolRunner.run(har, args)); + + //compare results + final List harPaths = lsr(shell, prefix + harName); + assertEquals(originalPaths, harPaths); + } + } + public void testPathWithSpaces() throws Exception { fs.delete(archivePath, true); @@ -170,8 +205,11 @@ private static List lsr(final FsShell shell, String dir System.setErr(oldErr); } System.out.println("lsr results:\n" + results); + String dirname = dir; + if (dir.lastIndexOf(Path.SEPARATOR) != -1 ) { + dirname = dir.substring(dir.lastIndexOf(Path.SEPARATOR)); + } - final String dirname = dir.substring(dir.lastIndexOf(Path.SEPARATOR)); final List paths = new ArrayList(); for(StringTokenizer t = new StringTokenizer(results, "\n"); t.hasMoreTokens(); ) {