HDFS-10474. hftp copy fails when file name with Chinese+special char in branch-2 (Contributed by Brahma Reddy Battula)

This commit is contained in:
Brahma Reddy Battula 2016-06-20 12:38:18 +05:30
parent ea4cab2330
commit 3f27f40503
4 changed files with 21 additions and 4 deletions

View File

@ -114,6 +114,21 @@ public static String encodePath(final String path) {
return new URIBuilder().setPath(path).toString();
}
/**
* Decode a string regarded as the path component of an URI.
*
* @param path the path component to decode
* @return decoded path, null if UTF-8 is not supported
* @throws URISyntaxException
*/
public static String decodePath(final String path) {
try {
return new URI(path).getPath();
} catch (URISyntaxException e) {
throw new AssertionError("Failed to decode URI: " + path);
}
}
/**
* Parse and decode the path component from the given request.
* @param request Http request to parse

View File

@ -442,12 +442,14 @@ public void startElement(String ns, String localname, String qname,
modif, atime, FsPermission.valueOf(attrs.getValue("permission")),
attrs.getValue("owner"), attrs.getValue("group"),
HftpFileSystem.this.makeQualified(
new Path(getUri().toString(), attrs.getValue("path"))))
new Path(getUri().toString(), ServletUtil.decodePath(
attrs.getValue("path")))))
: new FileStatus(0L, true, 0, 0L,
modif, atime, FsPermission.valueOf(attrs.getValue("permission")),
attrs.getValue("owner"), attrs.getValue("group"),
HftpFileSystem.this.makeQualified(
new Path(getUri().toString(), attrs.getValue("path"))));
new Path(getUri().toString(), ServletUtil.decodePath(
attrs.getValue("path")))));
fslist.add(fs);
}

View File

@ -69,7 +69,7 @@ static void writeInfo(final Path fullpath, final HdfsFileStatus i,
final XMLOutputter doc) throws IOException {
final SimpleDateFormat ldf = df.get();
doc.startTag(i.isDir() ? "directory" : "file");
doc.attribute("path", fullpath.toUri().getPath());
doc.attribute("path", ServletUtil.encodePath(fullpath.toUri().getPath()));
doc.attribute("modified", ldf.format(new Date(i.getModificationTime())));
doc.attribute("accesstime", ldf.format(new Date(i.getAccessTime())));
if (!i.isDir()) {

View File

@ -83,7 +83,7 @@ public class TestHftpFileSystem {
// URI percent encodes, Request#getPathInfo decodes
new Path("/foo bar/foo bar"), new Path("/foo?bar/foo?bar"),
new Path("/foo\">bar/foo\">bar"), };
new Path("/foo\">bar/foo\">bar"), new Path("/节节高@2X.png"), };
@BeforeClass
public static void setUp() throws Exception {