src/main/java/org/edgegallery/appstore/infrastructure/files/LocalFileServiceImpl.java
public static String sanitizeFileName(String entryName, String intendedDir) throws IOException {
        File f = new File(intendedDir, entryName);
        String canonicalPath = f.getCanonicalPath();
        File intendDir = new File(intendedDir);
        if (intendDir.isDirectory() && !intendDir.exists()) {
            createFile(intendedDir);
        }
        String canonicalID = intendDir.getCanonicalPath();
        if (canonicalPath.startsWith(canonicalID)) {
            return canonicalPath;
        } else {
            throw new FileOperateException("file is outside extraction target directory.",
                ResponseConst.RET_FILE_OUT_TARGET);
        }
    }
/**
     *sanitize file name.
     *
     * @param entryName entry name.
     * @parm  intendedDir parent dir
     */
sanitize file name.
@param entryName entry name.
@parm  intendedDir parent dir
sanitize file name . @param entryName entry name . @parm intendedDir parent dir
public static String sanitizeFileName(String entryName, String intendedDir) throws IOException {
        File f = new File(intendedDir, entryName);
        String canonicalPath = f.getCanonicalPath();
        File intendDir = new File(intendedDir);
        if (intendDir.isDirectory() && !intendDir.exists()) {
            createFile(intendedDir);
        }
        String canonicalID = intendDir.getCanonicalPath();
        if (canonicalPath.startsWith(canonicalID)) {
            return canonicalPath;
        } else {
            throw new FileOperateException("file is outside extraction target directory.",
                ResponseConst.RET_FILE_OUT_TARGET);
        }
    }
public static String sanitizeFileName ( String entryName , String intendedDir ) throws IOException { File f = new File ( intendedDir , entryName ) ; String canonicalPath = f . getCanonicalPath ( ) ; File intendDir = new File ( intendedDir ) ; if ( intendDir . isDirectory ( ) && ! intendDir . exists ( ) ) { createFile ( intendedDir ) ; } String canonicalID = intendDir . getCanonicalPath ( ) ; if ( canonicalPath . startsWith ( canonicalID ) ) { return canonicalPath ; } else { throw new FileOperateException ( "file is outside extraction target directory." , ResponseConst . RET_FILE_OUT_TARGET ) ; } }
sanitize file name.
sanitize file name .