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