returns the canonical form of path, if path doesn't start with one of
'/';cwd;a customRoot; or is a WindowsRoot then prepend cwd to path

@param path
@return canonical form of path
@throws SftpStatusException
176511
private String resolveRemotePath(String path) throws SftpStatusException {
		verifyConnection();

		String actual;
		if (!path.startsWith("/") && !path.startsWith(cwd)
				&& !isWindowsRoot(path) && !startsWithCustomRoot(path)) {
			actual = cwd + (cwd.endsWith("/") ? "" : "/") + path;
		} else {
			actual = path;
		}

		if (!actual.equals("/") && actual.endsWith("/")) {
			return actual.substring(0, actual.length() - 1);
		} else {
			return actual;
		}
	}
403020
@VisibleForTesting
  static String buildJcrPathForZip(final String path) {
    String normalizedPath = StringUtils.defaultString(path);
    if (!normalizedPath.startsWith("/")) {
      normalizedPath = "/" + normalizedPath;
    }
    return ROOT_DIR + PlatformNameFormat.getPlatformPath(normalizedPath);
  }
118762
public static UnixPath getPath(boolean permitEmptyComponents, String path) {
    if (path.isEmpty()) {
      return EMPTY_PATH;
    } else if (isRootInternal(path)) {
      return ROOT_PATH;
    } else {
      return new UnixPath(permitEmptyComponents, path);
    }
  }
1102941
public void lcd(String path) throws SftpStatusException {
		File actual;

		if (!isLocalAbsolutePath(path)) {
			actual = new File(lcwd, path);
		} else {
			actual = new File(path);
		}

		if (!actual.isDirectory()) {
			throw new SftpStatusException(SftpStatusException.SSH_FX_FAILURE,
					path + " is not a directory");
		}

		try {
			lcwd = actual.getCanonicalPath();
		} catch (IOException ex) {
			throw new SftpStatusException(SftpStatusException.SSH_FX_FAILURE,
					"Failed to canonicalize path " + path);
		}
	}
77971
public static String nativeDirectorySeparator(final String path) {
    if (path == null)
      return StringUtil.empty;
    return path.replace("/", directorySeparator).replace("\\", directorySeparator);
  }
373171
public static String encodePath(String path) {
        URI tmp;

        try {
            tmp = new URI("foo", "host", "/" + path, null);
        } catch (URISyntaxException e) {
            throw new IllegalStateException(e);
        }
        return tmp.getRawPath().substring(1);
    }
1142076
private static String getTrimmedPath(String path) {
        String result = path;
        if (result.endsWith("/")) {
            result = result.substring(0, result.length() - 1);
        }
        return result;
    }
432903
public static String canonical(String path) {
        if (path == null || path.length() == 0) {
            return path;
        }

        int end = path.length();
        int start = path.lastIndexOf('/', end);

        search:
        while (end > 0) {
            switch (end - start) {
                case 2: // possible single dot
                    if (path.charAt(start + 1) != '.') {
                        break;
                    }
                    break search;
                case 3: // possible double dot
                    if (path.charAt(start + 1) != '.' || path.charAt(start + 2) != '.') {
                        break;
                    }
                    break search;
            }

            end = start;
            start = path.lastIndexOf('/', end - 1);
        }

        // If we have checked the entire string
        if (start >= end) {
            return path;
        }

        StringBuilder buf = new StringBuilder(path);
        int delStart = -1;
        int delEnd = -1;
        int skip = 0;

        while (end > 0) {
            switch (end - start) {
                case 2: // possible single dot
                    if (buf.charAt(start + 1) != '.') {
                        if (skip > 0 && --skip == 0) {
                            delStart = start >= 0 ? start : 0;
                            if (delStart > 0 && delEnd == buf.length() && buf.charAt(delEnd - 1) == '.') {
                                delStart++;
                            }
                        }
                        break;
                    }

                    if (start < 0 && buf.length() > 2 && buf.charAt(1) == '/' && buf.charAt(2) == '/') {
                        break;
                    }

                    if (delEnd < 0) {
                        delEnd = end;
                    }
                    delStart = start;
                    if (delStart < 0 || delStart == 0 && buf.charAt(delStart) == '/') {
                        delStart++;
                        if (delEnd < buf.length() && buf.charAt(delEnd) == '/') {
                            delEnd++;
                        }
                        break;
                    }
                    if (end == buf.length()) {
                        delStart++;
                    }

                    end = start--;
                    while (start >= 0 && buf.charAt(start) != '/') {
                        start--;
                    }
                    continue;

                case 3: // possible double dot
                    if (buf.charAt(start + 1) != '.' || buf.charAt(start + 2) != '.') {
                        if (skip > 0 && --skip == 0) {
                            delStart = start >= 0 ? start : 0;
                            if (delStart > 0 && delEnd == buf.length() && buf.charAt(delEnd - 1) == '.') {
                                delStart++;
                            }
                        }
                        break;
                    }

                    delStart = start;
                    if (delEnd < 0) {
                        delEnd = end;
                    }

                    skip++;
                    end = start--;
                    while (start >= 0 && buf.charAt(start) != '/') {
                        start--;
                    }
                    continue;

                default:
                    if (skip > 0 && --skip == 0) {
                        delStart = start >= 0 ? start : 0;
                        if (delEnd == buf.length() && buf.charAt(delEnd - 1) == '.') {
                            delStart++;
                        }
                    }
            }

            // Do the delete
            if (skip <= 0 && delStart >= 0 && delEnd >= delStart) {
                buf.delete(delStart, delEnd);
                delStart = delEnd = -1;
            }

            end = start--;
            while (start >= 0 && buf.charAt(start) != '/') {
                start--;
            }
        }

        // Too many ..
        if (skip > 0) {
            return null;
        }

        // Do the delete
        if (delEnd >= 0) {
            buf.delete(delStart, delEnd);
        }

        return buf.toString();
    }
966341
public String getRealPath(String path) {
        if (context != null) {
            return context.getRealPath(path);
        }
        return path;
    }
1082372
public static final String posixString(Path path)
    {
        String prefix = path.isAbsolute() ? "/" : "";
        String suffix = Files.isDirectory(path) ? "/" : "";
        return StreamSupport.stream(path.spliterator(), false)
                .map((p)->p.toString())
                .collect(Collectors.joining("/", prefix, suffix));
    }
174783
@SuppressWarnings("UnusedLabel") // for documentation
    public static String canonicalize(final String path) {
        final int length = path.length();
        // 0 - start
        // 1 - got one .
        // 2 - got two .
        // 3 - got /
        int state = 0;
        if (length == 0) {
            return path;
        }
        final char[] targetBuf = new char[length];
        // string segment end exclusive
        int e = length;
        // string cursor position
        int i = length;
        // buffer cursor position
        int a = length - 1;
        // number of segments to skip
        int skip = 0;
        loop:
        while (--i >= 0) {
            char c = path.charAt(i);
            outer:
            switch (c) {
                case '/': {
                    inner:
                    switch (state) {
                        case 0:
                            state = 3;
                            e = i;
                            break outer;
                        case 1:
                            state = 3;
                            e = i;
                            break outer;
                        case 2:
                            state = 3;
                            e = i;
                            skip++;
                            break outer;
                        case 3:
                            e = i;
                            break outer;
                        default:
                            throw new IllegalStateException();
                    }
                    // not reached!
                }
                case '.': {
                    inner:
                    switch (state) {
                        case 0:
                            state = 1;
                            break outer;
                        case 1:
                            state = 2;
                            break outer;
                        case 2:
                            break inner; // emit!
                        case 3:
                            state = 1;
                            break outer;
                        default:
                            throw new IllegalStateException();
                    }
                    // fall thru
                }
                default: {
                    final int newE = e > 0 ? path.lastIndexOf('/', e - 1) : -1;
                    final int segmentLength = e - newE - 1;
                    if (skip > 0) {
                        skip--;
                    } else {
                        if (state == 3) {
                            targetBuf[a--] = '/';
                        }
                        path.getChars(newE + 1, e, targetBuf, (a -= segmentLength) + 1);
                    }
                    state = 0;
                    i = newE + 1;
                    e = newE;
                    break;
                }
            }
        }
        if (state == 3) {
            targetBuf[a--] = '/';
        }
        return new String(targetBuf, a + 1, length - a - 1);
    }
1156201
public boolean isHubPath(String path) throws IOException {
        if ("/".equals(path))
            return true;
        for (String root : getNonHubRoots()) {
            if (root.startsWith("*")) {
                if (path.endsWith(root.substring(1)))
                    return false;
            }
            else if (path.equals(root) || path.startsWith(root + "/")) {
                return false;
            }
        }
        return true;
    }
769116
public static String revisePath(String path) {
        if (!path.trim().equals("")) {
//            path = path.replaceAll("/", File.separator);
            File f = new File(path);
            if (f != null && !f.exists()) {
                f.mkdirs();
            }
            if (!f.isDirectory()) {
                f = f.getParentFile();
                path = f.getPath();
            }
            if (!path.endsWith(File.separator)) {
                path += File.separator;
            }
        }
        return path;
    }
1194366
@Nonnull
    public static Path getApprovalPath(Path filePath) {
        Pre.notNull(filePath, "filePath");

        String s = filePath.toString();
        int extensionIndex = s.lastIndexOf('.');

        if (extensionIndex == -1) {
            return Paths.get(s + FOR_APPROVAL_EXTENSION);
        }

        int lastPartOfPath = s.lastIndexOf('/');
        if (lastPartOfPath != -1 && lastPartOfPath > extensionIndex) {
            //there was no extension and the directory contains dots.
            return Paths.get(s + FOR_APPROVAL_EXTENSION);
        }

        String firstPart = s.substring(0, extensionIndex);
        String extension = s.substring(extensionIndex);

        return Paths.get(firstPart + FOR_APPROVAL_EXTENSION + extension);

    }
916128
def canonical_path(path):
        
        return os.path.normcase(os.path.realpath(os.path.abspath(
            os.path.expanduser(path))))
344589
public static String getRelativePathName(Path root, Path path) {
        Path relative = root.relativize(path);
        return Files.isDirectory(path) && !relative.toString().endsWith("/") ? String.format("%s/", relative.toString()) : relative.toString();
    }
751843
public String getFinalReason(Path path) {

		StringBuilder sb = new StringBuilder(path + " cannot be modified; ");
		StringBuilder finalPath = new StringBuilder("/");

		// Step through the nodes based on the given path. If any intermediate
		// nodes are marked as final, we can just return true.
		Node currentNode = root;
		for (Term t : path.getTerms()) {
			finalPath.append(t.toString());
			Node nextNode = currentNode.getChild(t);
			if (nextNode == null) {
				return null;
			} else if (nextNode.isFinal()) {
				sb.append(finalPath.toString() + " is marked as final");
				return sb.toString();
			}
			finalPath.append("/");
			currentNode = nextNode;
		}

		// Strip off the last slash. It is not needed.
		finalPath.deleteCharAt(finalPath.length() - 1);

		// Either the path itself is final or a descendant.
		if (currentNode.isFinal()) {
			sb.append(finalPath.toString() + " is marked as final");
		} else if (currentNode.hasChild()) {
			sb.append(finalPath.toString()
					+ currentNode.getFinalDescendantPath()
					+ " is marked as final");
			return sb.toString();
		} else {
			return null;
		}

		return null;
	}