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
This commit is contained in:
Chris Nauroth 2013-10-09 22:57:59 +00:00
parent 9b9ddf29e2
commit a75794567b
3 changed files with 38 additions and 2 deletions

View File

@ -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

View File

@ -84,13 +84,18 @@ protected void setPreserve(boolean preserve) {
*/
protected void getLocalDestination(LinkedList<String> args)
throws IOException {
try {
String pathString = (args.size() < 2) ? Path.CUR_DIR : args.removeLast();
try {
dst = new PathData(new URI(pathString), getConf());
} catch (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);
}
}
}
/**
* The last arg is expected to be a remote path, if only one argument is

View File

@ -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);