gitblit-org / gitblit

pure java git solution
http://gitblit.com
Apache License 2.0
2.28k stars 670 forks source link

NullPointer on inaccessible directories while searchRepositoriesSubfolders is true #347

Closed gitblit closed 9 years ago

gitblit commented 9 years ago

Originally reported on Google Code with ID 51

What steps will reproduce the problem?
1. Configure gitblit to search repositories in subfolders
2. Create an inaccessible folder inside the repositoriesFolder
3. Start and try to browse.

It handles in this case a 'lost+found' folder owned by root. But it can be any folder
(just create a folder and chmod it to 000).

What is the expected output? What do you see instead?

ERROR Can't instantiate page using constructor public com.gitblit.wicket.pages.RepositoriesPage()
org.apache.wicket.WicketRuntimeException: Can't instantiate page using constructor
public com.gitblit.wicket.pages.RepositoriesPage()
....
Caused by: java.lang.NullPointerException
        at com.gitblit.utils.JGitUtils.getRepositoryList(JGitUtils.java:329)
        at com.gitblit.utils.JGitUtils.getRepositoryList(JGitUtils.java:345)
        at com.gitblit.utils.JGitUtils.getRepositoryList(JGitUtils.java:306)
        at com.gitblit.GitBlit.getRepositoryList(GitBlit.java:645)
        at com.gitblit.GitBlit.getRepositoryModels(GitBlit.java:699)
        at com.gitblit.wicket.pages.RootPage.getRepositoryFilterItems(RootPage.java:220)
        at com.gitblit.wicket.pages.RepositoriesPage.addDropDownMenus(RepositoriesPage.java:99)
        at com.gitblit.wicket.pages.RootPage.setupPage(RootPage.java:112)
        at com.gitblit.wicket.pages.RepositoriesPage.setup(RepositoriesPage.java:61)
        at com.gitblit.wicket.pages.RepositoriesPage.<init>(RepositoriesPage.java:47)
        ... 37 more

What version of the product are you using? On what operating system?

Version 0.8.2 GO version on Linux.

Please provide any additional information below.

Reported by lemval on 2012-01-30 14:09:51

gitblit commented 9 years ago

Reported by James.Moger on 2012-01-30 14:28:45

gitblit commented 9 years ago
1- In which directory have the gitblt?
2- With what command you call it?

Seems as if it created the folders to another directory that is not the source. Linux
distribution, there are a lot of, what is yours?

Thks

Reported by eguervos on 2012-01-30 20:32:43

gitblit commented 9 years ago
Before answering your questions, I like to post the solution to this problem.

In file:
https://github.com/gitblit/gitblit/blob/master/src/com/gitblit/utils/JGitUtils.java
Method:
List<String> getRepositoryList(String basePath, File searchFolder, boolean exportAll,
boolean searchSubfolders)
On line:
} else if (searchSubfolders) {     --- 330 in github, 343 in google code, or the direct
link: http://code.google.com/p/gitblit/source/browse/src/com/gitblit/utils/JGitUtils.java#343

change this line to:
} else if (searchSubfolders && file.canRead()) {

This skips all directories which cannot be read. No sense in going deeper either.

----------
That said, the answer to your questions:
1. Linux version 2.6.32.24-0.2-default (geeko@buildhost) (gcc versio
n 4.3.4 [gcc-4_3-branch revision 152973] (SUSE Linux) ) x86_64 x86_64 x86_64 GNU/Linux
2. The error occurs on startup of gitlib when accessing the main page via https. No
repositories are shown.

I'm currently running a fixed version which seems to work fine.

Regards & thanks,
Michael

Reported by lemval on 2012-01-31 06:36:11

gitblit commented 9 years ago
Hi Michael,
I understood your issue.  I can merge your change in GitHub if you open a pull request.
 If you'd rather not go through the bother, that is ok too.

-James

Reported by James.Moger on 2012-01-31 12:51:38

gitblit commented 9 years ago
Quite easy as it seemed to aid you in a pull request. Here you are ;)

Reported by lemval on 2012-01-31 14:29:26

gitblit commented 9 years ago
Perfect!  Thanks for the patch.

Reported by James.Moger on 2012-01-31 15:01:02