Unverified Commit fd79be39 authored by lgcareer's avatar lgcareer Committed by GitHub
Browse files

verify whether the filename start with '/' (#2544)



* fix #2442 when the resource name contains '$',need translate it to '\$'

* fix #2442 when the resource name contains '$',need translate it to '/$'

* verify whether the filename start with '/'

Co-authored-by: default avatarqiaozhanwei <qiaozhanwei@outlook.com>
Co-authored-by: default avatardailidong <dailidong66@gmail.com>
parent 062a0ffb
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -503,6 +503,9 @@ public class HadoopUtils implements Closeable {
     * @return hdfs file name
     */
    public static String getHdfsFileName(ResourceType resourceType, String tenantCode, String fileName) {
        if (fileName.startsWith("/")) {
            fileName = fileName.replaceFirst("/","");
        }
        return String.format("%s/%s", getHdfsDir(resourceType,tenantCode), fileName);
    }

@@ -514,6 +517,9 @@ public class HadoopUtils implements Closeable {
     * @return get absolute path and name for file on hdfs
     */
    public static String getHdfsResourceFileName(String tenantCode, String fileName) {
        if (fileName.startsWith("/")) {
            fileName = fileName.replaceFirst("/","");
        }
        return String.format("%s/%s", getHdfsResDir(tenantCode), fileName);
    }

@@ -525,6 +531,9 @@ public class HadoopUtils implements Closeable {
     * @return get absolute path and name for udf file on hdfs
     */
    public static String getHdfsUdfFileName(String tenantCode, String fileName) {
        if (fileName.startsWith("/")) {
            fileName = fileName.replaceFirst("/","");
        }
        return String.format("%s/%s", getHdfsUdfDir(tenantCode), fileName);
    }

+12 −0
Original line number Diff line number Diff line
@@ -127,6 +127,18 @@ public class HadoopUtilsTest {
        Assert.assertEquals("/dolphinscheduler/11000/resources/aa.txt", result);
    }

    @Test
    public void getHdfsResourceFileName() {
        String result = hadoopUtils.getHdfsResourceFileName("11000","aa.txt");
        Assert.assertEquals("/dolphinscheduler/11000/resources/aa.txt", result);
    }

    @Test
    public void getHdfsUdfFileName() {
        String result = hadoopUtils.getHdfsFileName(ResourceType.UDF,"11000","aa.txt");
        Assert.assertEquals("/dolphinscheduler/11000/udfs/aa.txt", result);
    }

    @Test
    public void isYarnEnabled() {
        boolean result = hadoopUtils.isYarnEnabled();