summaryrefslogtreecommitdiffstats
path: root/src/main/java
diff options
context:
space:
mode:
authorJames Moger <james.moger@gitblit.com>2014-10-10 12:05:54 -0400
committerJames Moger <james.moger@gitblit.com>2014-10-10 12:05:54 -0400
commit461d90d607492d1b18ad8fa1e8a9984b2dc423f5 (patch)
tree4b2595a7814909fbd3745566b282375b4b67e1bf /src/main/java
parentc41962cda64d0cac37d4053c2120482b299dc7bd (diff)
parenta74ddc24545ec45d0bb82ca2bb8f628ffdaa9da3 (diff)
downloadgitblit-461d90d607492d1b18ad8fa1e8a9984b2dc423f5.tar.gz
gitblit-461d90d607492d1b18ad8fa1e8a9984b2dc423f5.zip
Merge branch 'ticket/204' into develop
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/gitblit/utils/FileUtils.java20
1 files changed, 6 insertions, 14 deletions
diff --git a/src/main/java/com/gitblit/utils/FileUtils.java b/src/main/java/com/gitblit/utils/FileUtils.java
index a1eb5bba..27caa7ea 100644
--- a/src/main/java/com/gitblit/utils/FileUtils.java
+++ b/src/main/java/com/gitblit/utils/FileUtils.java
@@ -26,6 +26,8 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.nio.charset.Charset;
+import java.nio.file.Path;
+import java.nio.file.Paths;
/**
* Common file utilities.
@@ -291,20 +293,10 @@ public class FileUtils {
* @return a relative path from basePath to path
*/
public static String getRelativePath(File basePath, File path) {
- File exactBase = getExactFile(basePath);
- File exactPath = getExactFile(path);
- if (path.getAbsolutePath().startsWith(basePath.getAbsolutePath())) {
- // absolute base-path match
- return StringUtils.getRelativePath(basePath.getAbsolutePath(), path.getAbsolutePath());
- } else 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());
+ Path exactBase = Paths.get(getExactFile(basePath).toURI());
+ Path exactPath = Paths.get(getExactFile(path).toURI());
+ if (exactPath.startsWith(exactBase)) {
+ return exactBase.relativize(exactPath).toString();
}
// no relative relationship
return null;