diff options
author | James Moger <james.moger@gitblit.com> | 2012-03-28 17:57:35 -0400 |
---|---|---|
committer | James Moger <james.moger@gitblit.com> | 2012-03-28 17:57:35 -0400 |
commit | 1aa6e081ffe319ff3ddfa246783cb65dc1c71b3b (patch) | |
tree | 15642ada937c47daf052a750807d7566c3216d70 /src/com/gitblit | |
parent | 6fdbc6b5bdb805d1faefe3f26105d5adfa37d5a1 (diff) | |
download | gitblit-1aa6e081ffe319ff3ddfa246783cb65dc1c71b3b.tar.gz gitblit-1aa6e081ffe319ff3ddfa246783cb65dc1c71b3b.zip |
Fixed symlink absolute path/canonical path mixup with JGit (issue 78)
Diffstat (limited to 'src/com/gitblit')
-rw-r--r-- | src/com/gitblit/GitServlet.java | 5 | ||||
-rw-r--r-- | src/com/gitblit/utils/FileUtils.java | 29 | ||||
-rw-r--r-- | src/com/gitblit/utils/JGitUtils.java | 4 |
3 files changed, 33 insertions, 5 deletions
diff --git a/src/com/gitblit/GitServlet.java b/src/com/gitblit/GitServlet.java index 3b60e9f1..73c6eaa4 100644 --- a/src/com/gitblit/GitServlet.java +++ b/src/com/gitblit/GitServlet.java @@ -50,6 +50,7 @@ import org.slf4j.LoggerFactory; import com.gitblit.models.RepositoryModel;
import com.gitblit.models.UserModel;
+import com.gitblit.utils.FileUtils;
import com.gitblit.utils.HttpUtils;
import com.gitblit.utils.StringUtils;
@@ -207,9 +208,7 @@ public class GitServlet extends org.eclipse.jgit.http.server.GitServlet { */
protected RepositoryModel getRepositoryModel(ReceivePack rp) {
Repository repository = rp.getRepository();
- String rootPath = GitBlit.getRepositoriesFolder().getAbsolutePath();
- String repositoryName = StringUtils.getRelativePath(rootPath, repository.getDirectory()
- .getAbsolutePath());
+ String repositoryName = FileUtils.getRelativePath(GitBlit.getRepositoriesFolder(), repository.getDirectory());
RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);
return model;
}
diff --git a/src/com/gitblit/utils/FileUtils.java b/src/com/gitblit/utils/FileUtils.java index 29c9d0fe..f8d35c84 100644 --- a/src/com/gitblit/utils/FileUtils.java +++ b/src/com/gitblit/utils/FileUtils.java @@ -149,4 +149,33 @@ public class FileUtils { }
}
}
+
+ /**
+ * Determine the relative path between two files. Takes into account
+ * canonical paths, if possible.
+ *
+ * @param basePath
+ * @param path
+ * @return a relative path from basePath to path
+ */
+ public static String getRelativePath(File basePath, File path) {
+ File exactBase = getExactFile(basePath);
+ File exactPath = getExactFile(path);
+ return StringUtils.getRelativePath(exactBase.getPath(), exactPath.getPath());
+ }
+
+ /**
+ * Returns the exact path for a file. This path will be the canonical path
+ * unless an exception is thrown in which case it will be the absolute path.
+ *
+ * @param path
+ * @return the exact file
+ */
+ public static File getExactFile(File path) {
+ try {
+ return path.getCanonicalFile();
+ } catch (IOException e) {
+ return path.getAbsoluteFile();
+ }
+ }
}
diff --git a/src/com/gitblit/utils/JGitUtils.java b/src/com/gitblit/utils/JGitUtils.java index f495a38f..72e948cc 100644 --- a/src/com/gitblit/utils/JGitUtils.java +++ b/src/com/gitblit/utils/JGitUtils.java @@ -301,6 +301,7 @@ public class JGitUtils { */
private static List<String> getRepositoryList(String basePath, File searchFolder,
boolean onlyBare, boolean searchSubfolders) {
+ File baseFile = new File(basePath);
List<String> list = new ArrayList<String>();
for (File file : searchFolder.listFiles()) {
if (file.isDirectory()) {
@@ -310,8 +311,7 @@ public class JGitUtils { continue;
}
// determine repository name relative to base path
- String repository = StringUtils.getRelativePath(basePath,
- file.getAbsolutePath());
+ String repository = FileUtils.getRelativePath(baseFile, file);
list.add(repository);
} else if (searchSubfolders && file.canRead()) {
// look for repositories in subfolders
|