]> source.dussan.org Git - gitblit.git/commitdiff
Fixes to relative path determination for symlinks (issue 116)
authorJames Moger <james.moger@gitblit.com>
Sat, 28 Jul 2012 01:41:26 +0000 (21:41 -0400)
committerJames Moger <james.moger@gitblit.com>
Sat, 28 Jul 2012 01:41:26 +0000 (21:41 -0400)
src/com/gitblit/utils/FileUtils.java

index a14928f2216b05c244cfb6e104f9115d3c8fb4a7..c291da6a347d8a32c158caf2689a8a086950e876 100644 (file)
@@ -226,7 +226,21 @@ public class FileUtils {
        public static String getRelativePath(File basePath, File path) {\r
                File exactBase = getExactFile(basePath);\r
                File exactPath = getExactFile(path);\r
-               return StringUtils.getRelativePath(exactBase.getPath(), exactPath.getPath());\r
+               if (exactPath.getPath().startsWith(exactBase.getPath())) {\r
+                       // canonical base-path match\r
+                       return StringUtils.getRelativePath(exactBase.getPath(), exactPath.getPath());\r
+               } else if (exactPath.getPath().startsWith(basePath.getAbsolutePath())) {\r
+                       // mixed path match\r
+                       return StringUtils.getRelativePath(basePath.getAbsolutePath(), exactPath.getPath());\r
+               } else if (path.getAbsolutePath().startsWith(exactBase.getPath())) {\r
+                       // mixed path match\r
+                       return StringUtils.getRelativePath(exactBase.getPath(), path.getAbsolutePath());\r
+               } else if (path.getAbsolutePath().startsWith(basePath.getAbsolutePath())) {\r
+                       // absolute base-path match\r
+                       return StringUtils.getRelativePath(basePath.getAbsolutePath(), path.getAbsolutePath());\r
+               }\r
+               // no relative relationship\r
+               return null;\r
        }\r
        \r
        /**\r