public static String findRootPath(String patternStr) {
        Path currentPath = Paths.get(patternStr);
        if (!Files.exists(currentPath)) {
            Path parentPath = currentPath.getParent();
            if (parentPath != null) {
                return findRootPath(parentPath.toString());
            }
        }
        if (Files.isDirectory(currentPath)) {
            return patternStr;
        }
        return currentPath.getParent().toString();
    }
Find the longest existing directory in the patternStr.Here are some examples:<br/>
<ul>
  <li>"/tmp/agent/1.txt" -> "/tmp/agent"
  <li>"/tmp/agent/*.txt" -> "/tmp/agent"
  <li>"/tmp/agent/**\/?.txt" -> "/tmp/agent"
  <li>"/tmp/agent" -> "/tmp/agent"
</ul>

@param patternStr
@return
inlong-agent/agent-common/src/main/java/org/apache/inlong/agent/utils/PathUtils.java