From: James Moger Date: Sat, 28 Jul 2012 01:41:26 +0000 (-0400) Subject: Fixes to relative path determination for symlinks (issue 116) X-Git-Tag: v1.1.0~48 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=5e010729291f732d4f31cbf66649dbac1e795a59;p=gitblit.git Fixes to relative path determination for symlinks (issue 116) --- diff --git a/src/com/gitblit/utils/FileUtils.java b/src/com/gitblit/utils/FileUtils.java index a14928f2..c291da6a 100644 --- a/src/com/gitblit/utils/FileUtils.java +++ b/src/com/gitblit/utils/FileUtils.java @@ -226,7 +226,21 @@ public class FileUtils { public static String getRelativePath(File basePath, File path) { File exactBase = getExactFile(basePath); File exactPath = getExactFile(path); - return StringUtils.getRelativePath(exactBase.getPath(), exactPath.getPath()); + if (exactPath.getPath().startsWith(exactBase.getPath())) { + // canonical base-path match + return StringUtils.getRelativePath(exactBase.getPath(), exactPath.getPath()); + } else if (exactPath.getPath().startsWith(basePath.getAbsolutePath())) { + // mixed path match + return StringUtils.getRelativePath(basePath.getAbsolutePath(), exactPath.getPath()); + } else if (path.getAbsolutePath().startsWith(exactBase.getPath())) { + // mixed path match + return StringUtils.getRelativePath(exactBase.getPath(), path.getAbsolutePath()); + } else if (path.getAbsolutePath().startsWith(basePath.getAbsolutePath())) { + // absolute base-path match + return StringUtils.getRelativePath(basePath.getAbsolutePath(), path.getAbsolutePath()); + } + // no relative relationship + return null; } /**