]> source.dussan.org Git - gitblit.git/commitdiff
Fixed symlink absolute path/canonical path mixup with JGit (issue 78)
authorJames Moger <james.moger@gitblit.com>
Wed, 28 Mar 2012 21:57:35 +0000 (17:57 -0400)
committerJames Moger <james.moger@gitblit.com>
Wed, 28 Mar 2012 21:57:35 +0000 (17:57 -0400)
docs/04_releases.mkd
src/com/gitblit/GitServlet.java
src/com/gitblit/utils/FileUtils.java
src/com/gitblit/utils/JGitUtils.java
tests/com/gitblit/tests/IssuesTest.java
tests/com/gitblit/tests/LuceneExecutorTest.java

index 51d3a1ac1d87ce4173419f9b778a65560d6000ed..322aed46ead027c8efd10f8f0d61f99c19ed7ad2 100644 (file)
@@ -6,6 +6,12 @@
 \r
 #### fixes\r
 \r
+- Fixed absolute path/canonical path discrepancy between Gitblit and JGit regarding use of symlinks (issue 78)\r
+\r
+**0.9.1** *released 2012-03-27*\r
+\r
+#### fixes\r
+\r
 - Lucene folder was stored in working copy instead of in .git folder\r
 \r
 **0.9.0** *released 2012-03-27*\r
index 3b60e9f1f3b29e63209204e99a88db53a70ec3ff..73c6eaa49cf1bc75f0b85ecb322da3216f5e018b 100644 (file)
@@ -50,6 +50,7 @@ import org.slf4j.LoggerFactory;
 \r
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.models.UserModel;\r
+import com.gitblit.utils.FileUtils;\r
 import com.gitblit.utils.HttpUtils;\r
 import com.gitblit.utils.StringUtils;\r
 \r
@@ -207,9 +208,7 @@ public class GitServlet extends org.eclipse.jgit.http.server.GitServlet {
                 */\r
                protected RepositoryModel getRepositoryModel(ReceivePack rp) {\r
                        Repository repository = rp.getRepository();\r
-                       String rootPath = GitBlit.getRepositoriesFolder().getAbsolutePath();\r
-                       String repositoryName = StringUtils.getRelativePath(rootPath, repository.getDirectory()\r
-                                       .getAbsolutePath());\r
+                       String repositoryName = FileUtils.getRelativePath(GitBlit.getRepositoriesFolder(), repository.getDirectory());\r
                        RepositoryModel model = GitBlit.self().getRepositoryModel(repositoryName);\r
                        return model;\r
                }\r
index 29c9d0fe64bfc782a0fd6e3b034f2b9f153ee956..f8d35c847a9a61fc055330b229825dc67967c2a2 100644 (file)
@@ -149,4 +149,33 @@ public class FileUtils {
                        }\r
                }\r
        }\r
+       \r
+       /**\r
+        * Determine the relative path between two files.  Takes into account\r
+        * canonical paths, if possible.\r
+        * \r
+        * @param basePath\r
+        * @param path\r
+        * @return a relative path from basePath to path\r
+        */\r
+       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
+       }\r
+       \r
+       /**\r
+        * Returns the exact path for a file. This path will be the canonical path\r
+        * unless an exception is thrown in which case it will be the absolute path.\r
+        * \r
+        * @param path\r
+        * @return the exact file\r
+        */\r
+       public static File getExactFile(File path) {\r
+               try {\r
+                       return path.getCanonicalFile();\r
+               } catch (IOException e) {\r
+                       return path.getAbsoluteFile();\r
+               }\r
+       }\r
 }\r
index f495a38f300cbaa726b8aba5cc3680be739c2987..72e948cce8c6d34578592ea0c215e6e35360d824 100644 (file)
@@ -301,6 +301,7 @@ public class JGitUtils {
         */\r
        private static List<String> getRepositoryList(String basePath, File searchFolder,\r
                        boolean onlyBare, boolean searchSubfolders) {\r
+               File baseFile = new File(basePath);\r
                List<String> list = new ArrayList<String>();\r
                for (File file : searchFolder.listFiles()) {\r
                        if (file.isDirectory()) {\r
@@ -310,8 +311,7 @@ public class JGitUtils {
                                                continue;\r
                                        }\r
                                        // determine repository name relative to base path\r
-                                       String repository = StringUtils.getRelativePath(basePath,\r
-                                                       file.getAbsolutePath());\r
+                                       String repository = FileUtils.getRelativePath(baseFile, file);\r
                                        list.add(repository);\r
                                } else if (searchSubfolders && file.canRead()) {\r
                                        // look for repositories in subfolders\r
index e329f6674560394671738bebd3c25dda621099ee..11f955146575c8917ea0a78bc9ce6a6e858c670f 100644 (file)
@@ -34,9 +34,9 @@ import com.gitblit.models.IssueModel.Field;
 import com.gitblit.models.IssueModel.Priority;\r
 import com.gitblit.models.IssueModel.Status;\r
 import com.gitblit.models.SearchResult;\r
+import com.gitblit.utils.FileUtils;\r
 import com.gitblit.utils.IssueUtils;\r
 import com.gitblit.utils.IssueUtils.IssueFilter;\r
-import com.gitblit.utils.StringUtils;\r
 \r
 /**\r
  * Tests the mechanics of distributed issue management on the gb-issues branch.\r
@@ -49,8 +49,7 @@ public class IssuesTest {
        @Test\r
        public void testLifecycle() throws Exception {\r
                Repository repository = GitBlitSuite.getIssuesTestRepository();\r
-               String name = StringUtils.getRelativePath(GitBlitSuite.REPOSITORIES.getAbsolutePath(),\r
-                               repository.getDirectory().getAbsolutePath());\r
+               String name = FileUtils.getRelativePath(GitBlitSuite.REPOSITORIES, repository.getDirectory());\r
                \r
                // create and insert an issue\r
                Change c1 = newChange("testCreation() " + Long.toHexString(System.currentTimeMillis()));\r
index d221744c5c1f0024eb92ef21cab59751833bb706..ec81fd8ec366b38a1a1af213a31ec8e64feaf08a 100644 (file)
@@ -23,10 +23,12 @@ import java.util.List;
 import org.eclipse.jgit.lib.Repository;\r
 import org.junit.Test;\r
 \r
+import com.gitblit.GitBlit;\r
 import com.gitblit.LuceneExecutor;\r
 import com.gitblit.models.RefModel;\r
 import com.gitblit.models.RepositoryModel;\r
 import com.gitblit.models.SearchResult;\r
+import com.gitblit.utils.FileUtils;\r
 import com.gitblit.utils.JGitUtils;\r
 import com.gitblit.utils.StringUtils;\r
 \r
@@ -44,8 +46,7 @@ public class LuceneExecutorTest {
        \r
        private RepositoryModel newRepositoryModel(Repository repository) {             \r
                RepositoryModel model = new RepositoryModel();\r
-               model.name = StringUtils.getRelativePath(GitBlitSuite.REPOSITORIES.getAbsolutePath(),\r
-                               repository.getDirectory().getAbsolutePath());\r
+               model.name = FileUtils.getRelativePath(GitBlitSuite.REPOSITORIES, repository.getDirectory());\r
                model.hasCommits = JGitUtils.hasCommits(repository);\r
                \r
                // index all local branches\r