# gitweb chokes on recursive symlink

2 messages from 2007-07-27 to 2007-07-27. Participants: Junio C Hamano, Jakub Narebski.
Thread: https://gitlist.dev/t/9254

## Junio C Hamano, 2007-07-27 08:23

Subject: gitweb chokes on recursive symlink
Message-ID: <7v8x922r2w.fsf@assigned-by-dhcp.cox.net>
URL: https://gitlist.dev/e/7v8x922r2w.fsf%40assigned-by-dhcp.cox.net

```
If somebody used to advertise his repository that physically
resides at /pub/lic.git/ as:

	git://git.example.com/pub/lic.git/

but now wants to use --base-path to allow:

	git://git.example.com/lic.git/

she can start git-daemon with --base-path option, like this:

	git-daemon --base-path=/pub --export-all

During the transition, however, she would also want to allow
older URL as well.  One natural way to achieve that is to create
a symlink:

	ln -s /pub /pub/pub

so that a request to git://git.example.com/pub/lic.git/ is first
translated by --base-path to a request to /pub/pub/lic.git/
which goes to /pub/lic.git, thanks to the symlink.

So far so good.

However, gitweb chokes if there is such a symlink (File::Find
barfs with "/pub/pub is a recursive symbolic link" --- I think
this is because you use "follow_fast => 1").

As I happen to think using a symlink that goes up for backward
compatible URL support is a rather common practice, I think we
should do something about it.  My gut feeling is that we could
simply ignore such symlinks.

What do you think about this issue?

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index b381692..c8ad84e 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1492,6 +1492,7 @@ sub git_get_projects_list {
 
 		File::Find::find({
 			follow_fast => 1, # follow symbolic links
+			follow_skip => 2, # ignore duplicates
 			dangling_symlinks => 0, # ignore dangling symlinks, silently
 			wanted => sub {
 				# skip project-list toplevel, if we get it.

	

```

## Jakub Narebski, 2007-07-27 22:57

Subject: Re: gitweb chokes on recursive symlink
Message-ID: <200707280057.22311.jnareb@gmail.com>
URL: https://gitlist.dev/e/200707280057.22311.jnareb%40gmail.com
In-Reply-To: <7v8x922r2w.fsf@assigned-by-dhcp.cox.net>

```
Junio C Hamano wrote:

[cut explanation about why one would want something like below]
 
> 	ln -s /pub /pub/pub
[...]
> However, gitweb chokes if there is such a symlink (File::Find
> barfs with "/pub/pub is a recursive symbolic link" --- I think
> this is because you use "follow_fast => 1").
> 
> As I happen to think using a symlink that goes up for backward
> compatible URL support is a rather common practice, I think we
> should do something about it.  My gut feeling is that we could
> simply ignore such symlinks.
> 
> What do you think about this issue?
> 
> diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
> index b381692..c8ad84e 100755
> --- a/gitweb/gitweb.perl
> +++ b/gitweb/gitweb.perl
> @@ -1492,6 +1492,7 @@ sub git_get_projects_list {
>  
>  		File::Find::find({
>  			follow_fast => 1, # follow symbolic links
> +			follow_skip => 2, # ignore duplicates
>  			dangling_symlinks => 0, # ignore dangling symlinks, silently
>  			wanted => sub {
>  				# skip project-list toplevel, if we get it.
> 

I guess that is a good solution, but I'm not Perl expert...

-- 
Jakub Narebski
Poland

```
