Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | From d33d46963035ef726144dc66be2ae9c00aec0333 Mon Sep 17 00:00:00 2001 |
| 2 | From: Niko Tyni <ntyni@debian.org> |
| 3 | Date: Tue, 16 Oct 2012 23:07:56 +0300 |
| 4 | Subject: Fix CPAN::FirstTime defaults with nonexisting site dirs if a parent |
| 5 | is writable |
| 6 | |
| 7 | The site directories do not exist on a typical Debian system. The build |
| 8 | systems will create them when necessary, so there's no need for a prompt |
| 9 | suggesting local::lib if the first existing parent directory is writable. |
| 10 | |
| 11 | Also, writability of the core directories is not interesting as we |
| 12 | explicitly tell CPAN not to touch those with INSTALLDIRS=site. |
| 13 | |
| 14 | Bug-Debian: http://bugs.debian.org/688842 |
| 15 | Patch-Name: debian/cpan-missing-site-dirs.diff |
| 16 | --- |
| 17 | cpan/CPAN/lib/CPAN/FirstTime.pm | 31 +++++++++++++++++++++++++++---- |
| 18 | 1 file changed, 27 insertions(+), 4 deletions(-) |
| 19 | |
| 20 | diff --git a/cpan/CPAN/lib/CPAN/FirstTime.pm b/cpan/CPAN/lib/CPAN/FirstTime.pm |
| 21 | index 33054cd..7b0becf 100644 |
| 22 | --- a/cpan/CPAN/lib/CPAN/FirstTime.pm |
| 23 | +++ b/cpan/CPAN/lib/CPAN/FirstTime.pm |
| 24 | @@ -2057,11 +2057,34 @@ sub _print_urllist { |
| 25 | }; |
| 26 | } |
| 27 | |
| 28 | +# Debian modification: return true if this directory |
| 29 | +# or the first existing one upwards is writable |
| 30 | +sub _can_write_to_this_or_parent { |
| 31 | + my ($dir) = @_; |
| 32 | + my @parts = File::Spec->splitdir($dir); |
| 33 | + while (@parts) { |
| 34 | + my $cur = File::Spec->catdir(@parts); |
| 35 | + return 1 if -w $cur; |
| 36 | + return 0 if -e _; |
| 37 | + pop @parts; |
| 38 | + } |
| 39 | + return 0; |
| 40 | +} |
| 41 | + |
| 42 | +# Debian specific modification: the site directories don't necessarily |
| 43 | +# exist on the system, but the build systems create them when necessary, |
| 44 | +# so return true if the first existing directory upwards is writable |
| 45 | +# |
| 46 | +# Furthermore, on Debian, only test the site directories |
| 47 | +# (installsite*, expanded to /usr/local/{share,lib}/perl), |
| 48 | +# not the core ones |
| 49 | +# (install*lib, expanded to /usr/{share,lib}/perl). |
| 50 | +# We pass INSTALLDIRS=site by default to keep CPAN from touching |
| 51 | +# the core directories. |
| 52 | + |
| 53 | sub _can_write_to_libdirs { |
| 54 | - return -w $Config{installprivlib} |
| 55 | - && -w $Config{installarchlib} |
| 56 | - && -w $Config{installsitelib} |
| 57 | - && -w $Config{installsitearch} |
| 58 | + return _can_write_to_this_or_parent($Config{installsitelib}) |
| 59 | + && _can_write_to_this_or_parent($Config{installsitearch}) |
| 60 | } |
| 61 | |
| 62 | sub _using_installbase { |