Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CPAN.pm error in Win32: uses rename() not File::Copy::move #6814

Closed
p5pRT opened this issue Oct 5, 2003 · 19 comments
Closed

CPAN.pm error in Win32: uses rename() not File::Copy::move #6814

p5pRT opened this issue Oct 5, 2003 · 19 comments

Comments

@p5pRT
Copy link

p5pRT commented Oct 5, 2003

Migrated from rt.perl.org#24119 (status was 'resolved')

Searchable as RT24119$

@p5pRT
Copy link
Author

p5pRT commented Oct 5, 2003

From pbwolf@bellatlantic.net

CPAN.pm (invoked as cpan in the command shell) reports a permission
problem trying to move a directory. The trouble is that CPAN.pm is using
the rename() function, which in Win32 can change a file's name but not
move it from one directory to another. A convenient solution is for
CPAN.pm to use File​::Copy​::move() instead. CPAN.pm already has a "use"
statement for File​::Copy anyway.

diff​:
3948c3948
< rename($distdir,$packagedir) or


    File&#8203;::Copy&#8203;::move\($distdir\,$packagedir\) or

CPAN.pm has many other instances of rename(). I haven't checked them.
But making the one change above made CPAN.pm function well enough to
install some modules.

This is a bug report for perl from pbwolf@​bellatlantic.net,
generated with the help of perlbug 1.34 running under perl v5.8.1.



Flags​:
  category=library
  severity=low


Site configuration information for perl v5.8.1​:

Configured by pbwolf at Sun Sep 28 22​:53​:03 2003.

Summary of my perl5 (revision 5 version 8 subversion 1) configuration​:
  Platform​:
  osname=MSWin32, osvers=4.0, archname=MSWin32-x86-multi-thread
  uname=''
  config_args='undef'
  hint=recommended, useposix=true, d_sigaction=undef
  usethreads=undef use5005threads=undef useithreads=define
usemultiplicity=define
  useperlio=define d_sfio=undef uselargefiles=define usesocks=undef
  use64bitint=undef use64bitall=undef uselongdouble=undef
  usemymalloc=n, bincompat5005=undef
  Compiler​:
  cc='cl', ccflags ='-MD -DNDEBUG -O1 -DWIN32 -D_CONSOLE -DNO_STRICT
-DHAVE_DES_FCRYPT -DPERL_IMPLICIT_CONTEXT -DPERL_IMPLICIT_SYS
-DPERL_MSVCRT_READFIX',
  optimize='-MD -DNDEBUG -O1',
  cppflags='-DWIN32'
  ccversion='', gccversion='', gccosandvers=''
  intsize=4, longsize=4, ptrsize=4, doublesize=8, byteorder=1234
  d_longlong=undef, longlongsize=8, d_longdbl=define, longdblsize=10
  ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='__int64',
lseeksize=8
  alignbytes=8, prototype=define
  Linker and Libraries​:
  ld='link', ldflags ='-nologo -nodefaultlib -release
-libpath​:"c​:\perl58\5.8.1\lib\MSWin32-x86-multi-thread\CORE"
-machine​:x86'
  libpth=\lib
  libs= oldnames.lib kernel32.lib user32.lib gdi32.lib winspool.lib
comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib
netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib version.lib
odbc32.lib odbccp32.lib msvcrt.lib
  perllibs= oldnames.lib kernel32.lib user32.lib gdi32.lib
winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib
oleaut32.lib netapi32.lib uuid.lib wsock32.lib mpr.lib winmm.lib
version.lib odbc32.lib odbccp32.lib msvcrt.lib
  libc=msvcrt.lib, so=dll, useshrplib=yes, libperl=perl58.lib
  gnulibc_version='undef'
  Dynamic Linking​:
  dlsrc=dl_win32.xs, dlext=dll, d_dlsymun=undef, ccdlflags=' '
  cccdlflags=' ', lddlflags='-dll -nologo -nodefaultlib -release
  -libpath​:"c​:\perl58\5.8.1\lib\MSWin32-x86-multi-thread\CORE"
-machine​:x86'

Locally applied patches​:
 


@​INC for perl v5.8.1​:
  C​:/perl58/5.8.1/lib/MSWin32-x86-multi-thread
  C​:/perl58/5.8.1/lib
  C​:/perl58/site/5.8.1/lib/MSWin32-x86-multi-thread
  C​:/perl58/site/5.8.1/lib
  .


Environment for perl v5.8.1​:
  HOME (unset)
  LANG (unset)
  LANGUAGE (unset)
  LD_LIBRARY_PATH (unset)
  LOGDIR (unset)
  PATH=bla bla bla
  PERL_BADLANG (unset)
  SHELL (unset)

@p5pRT
Copy link
Author

p5pRT commented Oct 6, 2003

From @eserte

Phill Wolf (via RT) <perlbug-followup@​perl.org> writes​:

# New Ticket Created by Phill Wolf
# Please include the string​: [perl #24119]
# in the subject line of all future correspondence about this issue.
# <URL​: http​://rt.perl.org/rt2/Ticket/Display.html?id=24119 >

CPAN.pm (invoked as cpan in the command shell) reports a permission
problem trying to move a directory. The trouble is that CPAN.pm is using
the rename() function, which in Win32 can change a file's name but not
move it from one directory to another.

In this case an entry for rename() in perlport.pod is also missing.

Regards,
  Slaven

--
Slaven Rezic - slaven@​rezic.de

  tkrevdiff - graphical display of diffs between revisions (RCS, CVS or SVN)
  http​://ptktools.sourceforge.net/#tkrevdiff

@p5pRT
Copy link
Author

p5pRT commented Apr 2, 2005

From schubiger@cpan.org

On 07 Oct 2003 00​:00​:13 +0200, Slaven Rezic <slaven@​rezic.de> wrote​:

:> CPAN.pm (invoked as cpan in the command shell) reports a permission
:> problem trying to move a directory. The trouble is that CPAN.pm is using
:> the rename() function, which in Win32 can change a file's name but not
:> move it from one directory to another.
:
: In this case an entry for rename() in perlport.pod is also missing.

Inline Patch
--- bleadperl/pod/perlport.pod	Fri Nov 12 22:13:04 2004
+++ perlport.pod		Sat Apr  2 23:29:09 2005
@@ -1836,6 +1836,10 @@
 
 Not implemented. (Win32, VMS, S<RISC OS>)
 
+=item rename OLDFILE,NEWFILE
+
+Can't move files. (Win32)
+
 =item select RBITS,WBITS,EBITS,TIMEOUT
 
 Only implemented on sockets. (Win32, VMS)

-- 

Steven Schubiger

@p5pRT
Copy link
Author

p5pRT commented Apr 3, 2005

From @jandubois

On Sat, 02 Apr 2005, Steven Schubiger wrote​:

On 07 Oct 2003 00​:00​:13 +0200, Slaven Rezic <slaven@​rezic.de> wrote​:

:> CPAN.pm (invoked as cpan in the command shell) reports a permission
:> problem trying to move a directory. The trouble is that CPAN.pm is using
:> the rename() function, which in Win32 can change a file's name but not
:> move it from one directory to another.
:
: In this case an entry for rename() in perlport.pod is also missing.

This is actually not exactly true. rename() can move files to different
directories on Win32 as long as source and destination are on the same
filesystem.

Cheers,
-Jan

--- bleadperl/pod/perlport.pod Fri Nov 12 22​:13​:04 2004
+++ perlport.pod Sat Apr 2 23​:29​:09 2005
@​@​ -1836,6 +1836,10 @​@​

Not implemented. (Win32, VMS, S<RISC OS>)

+=item rename OLDFILE,NEWFILE
+
+Can't move files. (Win32)
+
=item select RBITS,WBITS,EBITS,TIMEOUT

Only implemented on sockets. (Win32, VMS)

--
Steven Schubiger

@p5pRT
Copy link
Author

p5pRT commented Apr 3, 2005

From perl5-porters@ton.iguana.be

In article <200504022140.j32Le3uL010908@​accognoscere.homeunix.org>,
  Steven Schubiger <steven@​accognoscere.org> writes​:

On 07 Oct 2003 00​:00​:13 +0200, Slaven Rezic <slaven@​rezic.de> wrote​:

​:> CPAN.pm (invoked as cpan in the command shell) reports a permission
​:> problem trying to move a directory. The trouble is that CPAN.pm is using
​:> the rename() function, which in Win32 can change a file's name but not
​:> move it from one directory to another.
​:
​: In this case an entry for rename() in perlport.pod is also missing.

--- bleadperl/pod/perlport.pod Fri Nov 12 22​:13​:04 2004
+++ perlport.pod Sat Apr 2 23​:29​:09 2005
@​@​ -1836,6 +1836,10 @​@​

Not implemented. (Win32, VMS, S<RISC OS>)

+=item rename OLDFILE,NEWFILE
+
+Can't move files. (Win32)
I prefer​:
Can't move files between directories (Win32)

@p5pRT
Copy link
Author

p5pRT commented Apr 4, 2005

From @steve-m-hay

Jan Dubois wrote​:

On Sat, 02 Apr 2005, Steven Schubiger wrote​:

On 07 Oct 2003 00​:00​:13 +0200, Slaven Rezic <slaven@​rezic.de> wrote​:

​:> CPAN.pm (invoked as cpan in the command shell) reports a permission
​:> problem trying to move a directory. The trouble is that CPAN.pm is using
​:> the rename() function, which in Win32 can change a file's name but not
​:> move it from one directory to another.
​:
​: In this case an entry for rename() in perlport.pod is also missing.

This is actually not exactly true. rename() can move files to different
directories on Win32 as long as source and destination are on the same
filesystem.

On my WinXP box, rename() can move files to different directories,
including where those directories are on a different drive, a mapped
network drive from another WinXP box, and even a mapped network drive
from a Solaris box running Samba.

It seems to be rename()'ing directories that causes problems​:
sub-directories can be rename()'d from one parent directory to another
if and only if both parent directories are on the same drive.

- Steve


Radan Computational Ltd.

The information contained in this message and any files transmitted with it are confidential and intended for the addressee(s) only. If you have received this message in error or there are any problems, please notify the sender immediately. The unauthorized use, disclosure, copying or alteration of this message is strictly forbidden. Note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of Radan Computational Ltd. The recipient(s) of this message should check it and any attached files for viruses​: Radan Computational will accept no liability for any damage caused by any virus transmitted by this email.

@p5pRT
Copy link
Author

p5pRT commented Apr 4, 2005

From @steve-m-hay

Ton Hospel wrote​:

In article <200504022140.j32Le3uL010908@​accognoscere.homeunix.org>,
Steven Schubiger <steven@​accognoscere.org> writes​:

On 07 Oct 2003 00​:00​:13 +0200, Slaven Rezic <slaven@​rezic.de> wrote​:

​:> CPAN.pm (invoked as cpan in the command shell) reports a permission
​:> problem trying to move a directory. The trouble is that CPAN.pm is using
​:> the rename() function, which in Win32 can change a file's name but not
​:> move it from one directory to another.
​:
​: In this case an entry for rename() in perlport.pod is also missing.

--- bleadperl/pod/perlport.pod Fri Nov 12 22​:13​:04 2004
+++ perlport.pod Sat Apr 2 23​:29​:09 2005
@​@​ -1836,6 +1836,10 @​@​

Not implemented. (Win32, VMS, S<RISC OS>)

+=item rename OLDFILE,NEWFILE
+
+Can't move files. (Win32)

I prefer​:
Can't move files between directories (Win32)

How about​:

Can't move directories between directories on different drives (Win32)

?


Radan Computational Ltd.

The information contained in this message and any files transmitted with it are confidential and intended for the addressee(s) only. If you have received this message in error or there are any problems, please notify the sender immediately. The unauthorized use, disclosure, copying or alteration of this message is strictly forbidden. Note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of Radan Computational Ltd. The recipient(s) of this message should check it and any attached files for viruses​: Radan Computational will accept no liability for any damage caused by any virus transmitted by this email.

@p5pRT
Copy link
Author

p5pRT commented Apr 4, 2005

From @demerphq

On Apr 4, 2005 6​:28 PM, Steve Hay <steve.hay@​uk.radan.com> wrote​:

Ton Hospel wrote​:

In article <200504022140.j32Le3uL010908@​accognoscere.homeunix.org>,
Steven Schubiger <steven@​accognoscere.org> writes​:

On 07 Oct 2003 00​:00​:13 +0200, Slaven Rezic <slaven@​rezic.de> wrote​:

​:> CPAN.pm (invoked as cpan in the command shell) reports a permission
​:> problem trying to move a directory. The trouble is that CPAN.pm is using
​:> the rename() function, which in Win32 can change a file's name but not
​:> move it from one directory to another.
​:
​: In this case an entry for rename() in perlport.pod is also missing.

--- bleadperl/pod/perlport.pod Fri Nov 12 22​:13​:04 2004
+++ perlport.pod Sat Apr 2 23​:29​:09 2005
@​@​ -1836,6 +1836,10 @​@​

Not implemented. (Win32, VMS, S<RISC OS>)

+=item rename OLDFILE,NEWFILE
+
+Can't move files. (Win32)

I prefer​:
Can't move files between directories (Win32)

How about​:

Can't move directories between directories on different drives (Win32)

?

Shouldnt that be "logical volumes" or "logical devices"?

Yves

--
perl -Mre=debug -e "/just|another|perl|hacker/"

@p5pRT
Copy link
Author

p5pRT commented Apr 4, 2005

From @jandubois

On Mon, 04 Apr 2005, Steve Hay wrote​:

Jan Dubois wrote​:

This is actually not exactly true. rename() can move files to
different directories on Win32 as long as source and destination are
on the same filesystem.

On my WinXP box, rename() can move files to different directories,
including where those directories are on a different drive, a mapped
network drive from another WinXP box, and even a mapped network drive
from a Solaris box running Samba.

Yes, you are right. The limitation only applies to directories, which
can only be renamed but not actually moved.

I'm not sure if moving files to a different volume works under Win9X though,
and currently don't have access to a box to test (we have some duplicate
code in win32_rename() that uses MoveFileEx() only on WinNT, but uses the
C RTL rename() on Win95). The documentation for rename() doesn't mention
a limitation for Win95, but then we should be able to use MoveFileEx() there
too...

Cheers,
-Jan

@p5pRT
Copy link
Author

p5pRT commented Apr 5, 2005

From pbwolf@verizon.net

FYI, I was using W2K when I encountered the problem with the CPAN module's use of rename().

From​: Jan Dubois via RT <perlbug-followup@​perl.org>
Date​: Mon Apr 04 12​:34​:58 CDT 2005
To​: pbwolf@​bellatlantic.net
Subject​: RE​: [PATCH] Re​: [perl #24119] CPAN.pm error in Win32​: uses rename() not File​::Copy​::move

On Mon, 04 Apr 2005, Steve Hay wrote​:

Jan Dubois wrote​:

This is actually not exactly true. rename() can move files to
different directories on Win32 as long as source and destination are
on the same filesystem.

On my WinXP box, rename() can move files to different directories,
including where those directories are on a different drive, a mapped
network drive from another WinXP box, and even a mapped network drive
from a Solaris box running Samba.

Yes, you are right. The limitation only applies to directories, which
can only be renamed but not actually moved.

I'm not sure if moving files to a different volume works under Win9X though,
and currently don't have access to a box to test (we have some duplicate
code in win32_rename() that uses MoveFileEx() only on WinNT, but uses the
C RTL rename() on Win95). The documentation for rename() doesn't mention
a limitation for Win95, but then we should be able to use MoveFileEx() there
too...

Cheers,
-Jan

@p5pRT
Copy link
Author

p5pRT commented Apr 8, 2005

From schubiger@cpan.org

Attached is the improved patch.

Steven

@p5pRT
Copy link
Author

p5pRT commented Apr 8, 2005

From schubiger@cpan.org

perlport.pod.patch
--- perlport.pod.orig	Fri Nov 12 22:13:04 2004
+++ perlport.pod	Thu Apr  7 22:30:55 2005
@@ -1836,6 +1836,10 @@
 
 Not implemented. (Win32, VMS, S<RISC OS>)
 
+=item rename SOURCE,DESTINATION
+
+Can't move directories between directories on different logical volumes. (Win32)
+
 =item select RBITS,WBITS,EBITS,TIMEOUT
 
 Only implemented on sockets. (Win32, VMS)

@p5pRT
Copy link
Author

p5pRT commented Apr 8, 2005

From @steve-m-hay

Steven Schubiger wrote​:

Attached is the improved patch.

Thanks. Applied as 24209 (with the argument names changed to match
perlfunc.pod).

- Steve

Steven

------------------------------------------------
This email has been scanned for viruses and content by the Radan Computational Webshield Appliances.

------------------------------------------------------------------------

--- perlport.pod.orig Fri Nov 12 22​:13​:04 2004
+++ perlport.pod Thu Apr 7 22​:30​:55 2005
@​@​ -1836,6 +1836,10 @​@​

Not implemented. (Win32, VMS, S<RISC OS>)

+=item rename SOURCE,DESTINATION
+
+Can't move directories between directories on different logical volumes. (Win32)
+
=item select RBITS,WBITS,EBITS,TIMEOUT

Only implemented on sockets. (Win32, VMS)


Radan Computational Ltd.

The information contained in this message and any files transmitted with it are confidential and intended for the addressee(s) only. If you have received this message in error or there are any problems, please notify the sender immediately. The unauthorized use, disclosure, copying or alteration of this message is strictly forbidden. Note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of Radan Computational Ltd. The recipient(s) of this message should check it and any attached files for viruses​: Radan Computational will accept no liability for any damage caused by any virus transmitted by this email.

@p5pRT
Copy link
Author

p5pRT commented Jul 12, 2005

From @schwern

[pbwolf@​bellatlantic.net - Sun Oct 05 08​:06​:14 2003]​:

CPAN.pm (invoked as cpan in the command shell) reports a permission
problem trying to move a directory. The trouble is that CPAN.pm is using
the rename() function, which in Win32 can change a file's name but not
move it from one directory to another. A convenient solution is for
CPAN.pm to use File​::Copy​::move() instead. CPAN.pm already has a "use"
statement for File​::Copy anyway.

In all the discussion about the behavior of rename() on Win32 the
original point of this bug was lost. CPAN.pm is still riddled with
rename() calls.

@p5pRT
Copy link
Author

p5pRT commented Jul 12, 2005

From @schwern

The attached patch changes all the unsafe uses of rename() to
File​::Copy​::move(). These are the ones which move a path to a different
directory. All the rest work within the same dir and should be safe.

@p5pRT
Copy link
Author

p5pRT commented Jul 12, 2005

From @schwern

CPAN.pm.patch
--- lib/CPAN.pm	2005/07/12 06:21:13	1.3
+++ lib/CPAN.pm	2005/07/12 06:22:31
@@ -3977,9 +3977,9 @@
         -d $packagedir and $CPAN::Frontend->myprint("Removing previously used ".
                                                     "$packagedir\n");
         File::Path::rmtree($packagedir);
-        rename($distdir,$packagedir) or
-            Carp::confess("Couldn't rename $distdir to $packagedir: $!");
-        $self->debug(sprintf("renamed distdir[%s] to packagedir[%s] -e[%s]-d[%s]",
+        File::Copy::move($distdir,$packagedir) or
+            Carp::confess("Couldn't move $distdir to $packagedir: $!");
+        $self->debug(sprintf("moved distdir[%s] to packagedir[%s] -e[%s]-d[%s]",
                              $distdir,
                              $packagedir,
                              -e $packagedir,
@@ -4000,7 +4000,7 @@
         my($f);
         for $f (@readdir) { # is already without "." and ".."
             my $to = File::Spec->catdir($packagedir,$f);
-            rename($f,$to) or Carp::confess("Couldn't rename $f to $to: $!");
+            File::Copy::move($f,$to) or Carp::confess("Couldn't move $f to $to: $!");
         }
     }
     if ($CPAN::Signal){

@p5pRT
Copy link
Author

p5pRT commented Jul 12, 2005

From @steve-m-hay

Michael G Schwern via RT wrote​:

The attached patch changes all the unsafe uses of rename() to
File​::Copy​::move(). These are the ones which move a path to a different
directory. All the rest work within the same dir and should be safe.

Thanks. Applied as change 25125.


Radan Computational Ltd.

The information contained in this message and any files transmitted with it are confidential and intended for the addressee(s) only. If you have received this message in error or there are any problems, please notify the sender immediately. The unauthorized use, disclosure, copying or alteration of this message is strictly forbidden. Note that any views or opinions presented in this email are solely those of the author and do not necessarily represent those of Radan Computational Ltd. The recipient(s) of this message should check it and any attached files for viruses​: Radan Computational will accept no liability for any damage caused by any virus transmitted by this email.

@p5pRT
Copy link
Author

p5pRT commented Jul 12, 2005

From @steve-m-hay

Now fixed in bleadperl so should be in 5.8.8, otherwise in 5.10.

@p5pRT
Copy link
Author

p5pRT commented Jul 12, 2005

@steve-m-hay - Status changed from 'open' to 'resolved'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant