From a75794567bd029cd54281fb01800df2ea362a187 Mon Sep 17 00:00:00 2001 From: Chris Nauroth Date: Wed, 9 Oct 2013 22:57:59 +0000 Subject: [PATCH] HADOOP-10031. FsShell -get/copyToLocal/moveFromLocal should support Windows local path. Contributed by Chuan Liu. git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1530823 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop-common/CHANGES.txt | 3 ++ .../fs/shell/CommandWithDestination.java | 9 ++++-- .../org/apache/hadoop/fs/TestFsShellCopy.java | 28 +++++++++++++++++++ 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/hadoop-common-project/hadoop-common/CHANGES.txt b/hadoop-common-project/hadoop-common/CHANGES.txt index 76f820ec10..0112c6d858 100644 --- a/hadoop-common-project/hadoop-common/CHANGES.txt +++ b/hadoop-common-project/hadoop-common/CHANGES.txt @@ -413,6 +413,9 @@ Release 2.2.1 - UNRELEASED HADOOP-10030. FsShell -put/copyFromLocal should support Windows local path. (Chuan Liu via cnauroth) + HADOOP-10031. FsShell -get/copyToLocal/moveFromLocal should support Windows + local path. (Chuan Liu via cnauroth) + Release 2.2.0 - 2013-10-13 INCOMPATIBLE CHANGES diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java index 9664bdd03e..1684ec53a5 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java @@ -84,11 +84,16 @@ protected void setPreserve(boolean preserve) { */ protected void getLocalDestination(LinkedList args) throws IOException { + String pathString = (args.size() < 2) ? Path.CUR_DIR : args.removeLast(); try { - String pathString = (args.size() < 2) ? Path.CUR_DIR : args.removeLast(); dst = new PathData(new URI(pathString), getConf()); } catch (URISyntaxException e) { - throw new IOException("unexpected URISyntaxException", e); + if (Path.WINDOWS) { + // Unlike URI, PathData knows how to parse Windows drive-letter paths. + dst = new PathData(pathString, getConf()); + } else { + throw new IOException("unexpected URISyntaxException", e); + } } } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFsShellCopy.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFsShellCopy.java index dbdb7da101..bef0c9fc01 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFsShellCopy.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFsShellCopy.java @@ -457,6 +457,34 @@ public void testMoveDirFromLocalDestExists() throws Exception { assertTrue(lfs.exists(srcDir)); } + @Test + public void testMoveFromWindowsLocalPath() throws Exception { + assumeTrue(Path.WINDOWS); + Path testRoot = new Path(testRootDir, "testPutFile"); + lfs.delete(testRoot, true); + lfs.mkdirs(testRoot); + + Path target = new Path(testRoot, "target"); + Path srcFile = new Path(testRoot, new Path("srcFile")); + lfs.createNewFile(srcFile); + + String winSrcFile = (new File(srcFile.toUri().getPath() + .toString())).getAbsolutePath(); + shellRun(0, "-moveFromLocal", winSrcFile, target.toString()); + assertFalse(lfs.exists(srcFile)); + assertTrue(lfs.exists(target)); + assertTrue(lfs.isFile(target)); + } + + @Test + public void testGetWindowsLocalPath() throws Exception { + assumeTrue(Path.WINDOWS); + String winDstFile = (new File(dstPath.toUri().getPath() + .toString())).getAbsolutePath(); + shellRun(0, "-get", srcPath.toString(), winDstFile); + checkPath(dstPath, false); + } + private void createFile(Path ... paths) throws IOException { for (Path path : paths) { FSDataOutputStream out = lfs.create(path);