HDFS-10474. hftp copy fails when file name with Chinese+special char in branch-2 (Contributed by Brahma Reddy Battula)
(cherry picked from commit 3f27f40503
)
This commit is contained in:
parent
55658dcaa3
commit
9d27530c36
|
@ -114,6 +114,21 @@ public class ServletUtil {
|
||||||
return new URIBuilder().setPath(path).toString();
|
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.
|
* Parse and decode the path component from the given request.
|
||||||
* @param request Http request to parse
|
* @param request Http request to parse
|
||||||
|
|
|
@ -442,12 +442,14 @@ public class HftpFileSystem extends FileSystem
|
||||||
modif, atime, FsPermission.valueOf(attrs.getValue("permission")),
|
modif, atime, FsPermission.valueOf(attrs.getValue("permission")),
|
||||||
attrs.getValue("owner"), attrs.getValue("group"),
|
attrs.getValue("owner"), attrs.getValue("group"),
|
||||||
HftpFileSystem.this.makeQualified(
|
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,
|
: new FileStatus(0L, true, 0, 0L,
|
||||||
modif, atime, FsPermission.valueOf(attrs.getValue("permission")),
|
modif, atime, FsPermission.valueOf(attrs.getValue("permission")),
|
||||||
attrs.getValue("owner"), attrs.getValue("group"),
|
attrs.getValue("owner"), attrs.getValue("group"),
|
||||||
HftpFileSystem.this.makeQualified(
|
HftpFileSystem.this.makeQualified(
|
||||||
new Path(getUri().toString(), attrs.getValue("path"))));
|
new Path(getUri().toString(), ServletUtil.decodePath(
|
||||||
|
attrs.getValue("path")))));
|
||||||
fslist.add(fs);
|
fslist.add(fs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,7 +69,7 @@ public class ListPathsServlet extends DfsServlet {
|
||||||
final XMLOutputter doc) throws IOException {
|
final XMLOutputter doc) throws IOException {
|
||||||
final SimpleDateFormat ldf = df.get();
|
final SimpleDateFormat ldf = df.get();
|
||||||
doc.startTag(i.isDir() ? "directory" : "file");
|
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("modified", ldf.format(new Date(i.getModificationTime())));
|
||||||
doc.attribute("accesstime", ldf.format(new Date(i.getAccessTime())));
|
doc.attribute("accesstime", ldf.format(new Date(i.getAccessTime())));
|
||||||
if (!i.isDir()) {
|
if (!i.isDir()) {
|
||||||
|
|
|
@ -83,7 +83,7 @@ public class TestHftpFileSystem {
|
||||||
|
|
||||||
// URI percent encodes, Request#getPathInfo decodes
|
// 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("/foo\">bar/foo\">bar"), };
|
new Path("/foo\">bar/foo\">bar"), new Path("/节节高@2X.png"), };
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setUp() throws Exception {
|
public static void setUp() throws Exception {
|
||||||
|
|
Loading…
Reference in New Issue