perl5-changes  

Change 32006: [PATCH - 2nd revision] /cygdrive is configurable

Rafael Garcia-Suarez
Tue, 02 Oct 2007 05:45:39 -0700

Change 32006 by [EMAIL PROTECTED] on 2007/10/02 12:31:32

        Subject: [PATCH - 2nd revision] /cygdrive is configurable
        From: "Jerry D. Hedden" <[EMAIL PROTECTED]>
        Date: Mon, 1 Oct 2007 19:32:19 -0400
        Message-ID: <[EMAIL PROTECTED]>

Affected files ...

... //depot/perl/README.cygwin#42 edit
... //depot/perl/cygwin/cygwin.c#21 edit
... //depot/perl/lib/File/Spec/Cygwin.pm#19 edit
... //depot/perl/t/lib/cygwin.t#7 edit

Differences ...

==== //depot/perl/README.cygwin#42 (text) ====
Index: perl/README.cygwin
--- perl/README.cygwin#41~31972~        2007-09-26 01:20:14.000000000 -0700
+++ perl/README.cygwin  2007-10-02 05:31:32.000000000 -0700
@@ -514,14 +514,15 @@
   system|user,binmode|textmode,exec,cygexec,cygdrive,mixed,
   notexec,managed,nosuid,devfs,proc,noumount
 
-If the argument is "/cygdrive", just the volume mount settings are returned.
+If the argument is "/cygdrive", then just the volume mount settings,
+and the cygdrive mount prefix are returned.
 
 User mounts override system mounts.
 
   $ perl -e 'print Cygwin::mount_flags "/usr/bin"'
   system,binmode,cygexec
   $ perl -e 'print Cygwin::mount_flags "/cygdrive"'
-  binmode,cygdrive
+  binmode,cygdrive,/cygdrive
 
 =item C<Cygwin::is_binmount>
 

==== //depot/perl/cygwin/cygwin.c#21 (text) ====
Index: perl/cygwin/cygwin.c
--- perl/cygwin/cygwin.c#20~31773~      2007-08-31 06:28:46.000000000 -0700
+++ perl/cygwin/cygwin.c        2007-10-02 05:31:32.000000000 -0700
@@ -292,28 +292,31 @@
     char flags[260];
 
     if (items != 1)
-        Perl_croak(aTHX_ "Usage: Cygwin::mount_flags(mnt_dir)");
+        Perl_croak(aTHX_ "Usage: Cygwin::mount_flags(mnt_dir|'/cygwin')");
 
     pathname = SvPV_nolen(ST(0));
-    
-    /* TODO: check for cygdrive registry setting. use CW_GET_CYGDRIVE_INFO then
+
+    /* TODO: Check for cygdrive registry setting,
+     *       and then use CW_GET_CYGDRIVE_INFO
      */
     if (!strcmp(pathname, "/cygdrive")) {
        char user[260];
        char system[260];
        char user_flags[260];
        char system_flags[260];
+
        cygwin_internal (CW_GET_CYGDRIVE_INFO, user, system, user_flags,
                         system_flags);
-       if (strlen(system) > 0)
-           strcpy (flags, system_flags);
-       if (strlen(user) > 0)
-           strcpy(flags, user_flags);
-       if (strlen(flags) > 0)
-           strcat(flags, ",");
-       strcat(flags, "cygdrive");
+
+        if (strlen(user) > 0) {
+            sprintf(flags, "%s,cygdrive,%s", user_flags, user);
+        } else {
+            sprintf(flags, "%s,cygdrive,%s", system_flags, system);
+        }
+
        ST(0) = sv_2mortal(newSVpv(flags, 0));
        XSRETURN(1);
+
     } else {
        struct mntent *mnt;
        setmntent (0, 0);

==== //depot/perl/lib/File/Spec/Cygwin.pm#19 (text) ====
Index: perl/lib/File/Spec/Cygwin.pm
--- perl/lib/File/Spec/Cygwin.pm#18~31720~      2007-08-15 03:06:20.000000000 
-0700
+++ perl/lib/File/Spec/Cygwin.pm        2007-10-02 05:31:32.000000000 -0700
@@ -4,7 +4,7 @@
 use vars qw(@ISA $VERSION);
 require File::Spec::Unix;
 
-$VERSION = '1.1_02';
+$VERSION = '1.1_03';
 
 @ISA = qw(File::Spec::Unix);
 
@@ -112,7 +112,18 @@
   if ($^O ne 'cygwin') {
     return 1;
   }
-  my $drive = shift || "/cygdrive/c";
+  my $drive = shift;
+  if (! $drive) {
+      my @flags = split(/,/, Cygwin::mount_flags('/cygwin'));
+      my $prefix = pop(@flags);
+      if (! $prefix || $prefix eq 'cygdrive') {
+          $drive = '/cygdrive/c';
+      } elsif ($prefix eq '/') {
+          $drive = '/c';
+      } else {
+          $drive = "$prefix/c";
+      }
+  }
   my $mntopts = Cygwin::mount_flags($drive);
   if ($mntopts and ($mntopts =~ /,managed/)) {
     return 0;

==== //depot/perl/t/lib/cygwin.t#7 (text) ====
Index: perl/t/lib/cygwin.t
--- perl/t/lib/cygwin.t#6~31773~        2007-08-31 06:28:46.000000000 -0700
+++ perl/t/lib/cygwin.t 2007-10-02 05:31:32.000000000 -0700
@@ -9,7 +9,7 @@
     }
 }
 
-use Test::More tests => 14;
+use Test::More tests => 16;
 
 is(Cygwin::winpid_to_pid(Cygwin::pid_to_winpid($$)), $$,
    "perl pid translates to itself");
@@ -51,6 +51,17 @@
 ok($binmode ? ($rootmnt =~ /,binmode/) : ($rootmnt =~ /,textmode/), "check / 
mount_flags");
 is(Cygwin::mount_flags("/cygdrive") =~ /,cygdrive/,  1, "check cygdrive 
mount_flags");
 
+# Cygdrive mount prefix
+my @flags = split(/,/, Cygwin::mount_flags('/cygdrive'));
+my $prefix = pop(@flags);
+ok($prefix, "cygdrive mount prefix = " . (($prefix) ? $prefix : '<none>'));
+chomp(my $prefix2 = `df | grep -i '^c: ' | cut -d% -f2 | xargs`);
+$prefix2 =~ s/\/c$//i;
+if (! $prefix2) {
+    $prefix2 = '/';
+}
+is($prefix, $prefix2, 'cygdrive mount prefix');
+
 my @mnttbl = Cygwin::mount_table();
 ok(@mnttbl > 0, "non empty mount_table");
 for $i (@mnttbl) {
End of Patch.
  • Change 32006: [PATCH - 2nd revision] /cygdrive is configurable Rafael Garcia-Suarez