tag 688842 patch
thanks

On Wed, Oct 03, 2012 at 11:41:30AM +0300, Niko Tyni wrote:
> On Wed, Sep 26, 2012 at 09:12:00AM +0300, Niko Tyni wrote:

> > When the site dirs don't exist, the CPAN shell interactive configuration 
> > states
> >   Warning: You do not have write permission for Perl library directories.
> > and proceeds to suggest local::lib for installation, which is not the
> > optimal suggestion for root users.

> My current thinking is that a minimally invasive fix would be a loop
> that tests the first existing directory up the tree for writability.
> This way we can leave the mkdir part (along with umask settings,
> see debian/patches/debian/writable_site_dirs.diff) for later.

Looking at the issue, I realized that we don't want to test the
writability of the core dirs (install*lib) on Debian at all. We're
configuring CPAN to pass INSTALLDIRS=site precisely to keep it from
touching the core directories.

This way root and non-root users who have write access to /usr/local
will get the right default (system-wide install), and the rest will be
prompted about using local::lib or sudo.

Here's my first take on a patch. It seems to work, but eyeballs
and testing would be welcome.

While I've marked the patch as Debian specific, I tried to keep the
directory name handling portable in the hope at least part of it can go
upstream at some point.
-- 
Niko Tyni   nt...@debian.org
>From 4958de89499744f4fc439014edf14b64234a7b23 Mon Sep 17 00:00:00 2001
From: Niko Tyni <nt...@debian.org>
Date: Tue, 16 Oct 2012 23:07:56 +0300
Subject: Fix CPAN::FirstTime defaults with nonexisting site dirs if a parent
 is writable

The site directories do not exist on a typical Debian system.  The build
systems will create them when necessary, so there's no need for a prompt
suggesting local::lib if the first existing parent directory is writable.

Also, writability of the core directories is not interesting as we
explicitly tell CPAN not to touch those with INSTALLDIRS=site.

Bug-Debian: http://bugs.debian.org/688842
Patch-Name: debian/cpan-missing-site-dirs.diff
---
 cpan/CPAN/lib/CPAN/FirstTime.pm |   31 +++++++++++++++++++++++++++----
 1 file changed, 27 insertions(+), 4 deletions(-)

diff --git a/cpan/CPAN/lib/CPAN/FirstTime.pm b/cpan/CPAN/lib/CPAN/FirstTime.pm
index c38c890..bca3c8f 100644
--- a/cpan/CPAN/lib/CPAN/FirstTime.pm
+++ b/cpan/CPAN/lib/CPAN/FirstTime.pm
@@ -2003,11 +2003,34 @@ sub _print_urllist {
     };
 }
 
+# Debian modification: return true if this directory
+# or the first existing one upwards is writable
+sub _can_write_to_this_or_parent {
+    my ($dir) = @_;
+    my @parts = File::Spec->splitdir($dir);
+    while (@parts) {
+        my $cur = File::Spec->catdir(@parts);
+        return 1 if -w $cur;
+        return 0 if -e _;
+        pop @parts;
+    }
+    return 0;
+}
+
+# Debian specific modification: the site directories don't necessarily
+# exist on the system, but the build systems create them when necessary,
+# so return true if the first existing directory upwards is writable
+#
+# Furthermore, on Debian, only test the site directories
+# (installsite*, expanded to /usr/local/{share,lib}/perl),
+# not the core ones 
+# (install*lib, expanded to /usr/{share,lib}/perl).
+# We pass INSTALLDIRS=site by default to keep CPAN from touching
+# the core directories.
+
 sub _can_write_to_libdirs {
-    return -w $Config{installprivlib}
-        && -w $Config{installarchlib}
-        && -w $Config{installsitelib}
-        && -w $Config{installsitearch}
+    return _can_write_to_this_or_parent($Config{installsitelib})
+        && _can_write_to_this_or_parent($Config{installsitearch})
 }
 
 sub _using_installbase {

Reply via email to