Perl / perl5

🐪 The Perl programming language
https://dev.perl.org/perl5/
Other
1.88k stars 530 forks source link

Perl function "rename oldname, newname" eats network files #730

Closed p5pRT closed 20 years ago

p5pRT commented 24 years ago

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

Searchable as RT1642$

p5pRT commented 24 years ago

From andy.d.andrea@ontariopowergeneration.com

The "rename oldname\, newname" function was being used to rename all files in a directory that were named in lowercase or a lower/uppercase mix to all uppercase.

The following code stops when the rename fails the first time. This code is being run on a networked NT 4 system. The problem occurs when running the script on a network directory containing about 20 files having lower case character in their names. It doesn't seem to be a problem if working on a local hard disk.

The file being worked on when rename fails is deleted from the filesystem!

Please let me know if fixed patch exists.

  Andy D'Andrea

#!/usr/bin/perl ############################################################ toupper # ##################################################################### $cnt = 0; foreach (\<*>) {   ++$cnt;   $oldname = $_;   tr/a-z/A-Z/;   $newname = $_;   if( $newname ne $oldname) {   (-e $oldname) ? print "$oldname -> $newname\, ok?"​: die "$oldname not there \n";   $goahead = \;   (rename $oldname\, $newname ) ? print " ...done. \n" : die ("whoa\, too fast for the network? $! \n");   } }


Site configuration information for perl 5.00503​:

Summary of my perl5 (5.0 patchlevel 5 subversion 03) configuration​:   Platform​:   osname=MSWin32\, osvers=4.0\, archname=MSWin32-x86-object   uname=''   hint=recommended\, useposix=true\, d_sigaction=undef   usethreads=undef useperlio=undef d_sfio=undef   Compiler​:   cc='cl.exe'\, optimize='-Od -MD -DNDEBUG -TP -GX'\, gccversion=   cppflags='-DWIN32'   ccflags ='-Od -MD -DNDEBUG -TP -GX -DWIN32 -D_CONSOLE -DNO_STRICT -DHAVE_DES_FCRYPT -DPERL_OBJECT'   stdchar='char'\, d_stdstdio=define\, usevfork=false   intsize=4\, longsize=4\, ptrsize=4\, doublesize=8   d_longlong=undef\, longlongsize=8\, d_longdbl=define\, longdblsize=10   alignbytes=8\, usemymalloc=n\, prototype=define   Linker and Libraries​:   ld='link'\, ldflags ='-nologo -nodefaultlib -release -machine​:x86'   libpth="C​:\Tools\Perl\lib\core" "e​:\ntapps\devstudio\vc\lib" "e​:\ntapps\devstudio\vc\mfc\lib" "d​:\program files\devstudio\vc\lib" "d​:\program files\devstudio\vc\mfc\lib" "%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 PerlCRT.lib   libc=C​:\Tools\Perl\lib\CORE\PerlCRT.lib\, so=dll\, useshrplib=yes\, libperl=perlcore.lib   Dynamic Linking​:   dlsrc=dl_win32.xs\, dlext=dll\, d_dlsymun=undef\, ccdlflags=' '   cccdlflags=' '\, lddlflags='-dll -nologo -nodefaultlib -release -machine​:x86'

Locally applied patches​:   ACTIVEPERL_LOCAL_PATCHES_ENTRY


@​INC for perl 5.00503​:   C​:/Tools/Perl/lib   C​:/Tools/Perl/site/lib   .


Environment for perl 5.00503​:   HOME (unset)   LANG (unset)   LANGUAGE (unset)   LD_LIBRARY_PATH (unset)   LOGDIR (unset)   PATH=C​:\Program Files\DevStudio\SharedIDE\BIN;c​:\Program Files\DevStudio\VF\BIN;c​:\Program Files\DevStudio\VC\BIN;C​:\Tools\Perl\bin;C​:\WINNT\system32;C​:\WINNT;F​:\ORANT \BIN;F​:\ORAWIN\BIN;F​:\SQLW502;C​:\PROGRAM FILES\TOOLKIT;c​:\PROGRAM FILES\toolkit;c​:\program files\toolkit;F​:\CENTURA;C​:\Program Files\Mts   PERL_BADLANG (unset)   SHELL (unset)

Andy D'Andrea Associate Engineer Long-term Waste Management Technology Department Nuclear Waste Management * andy.d.andrea@​ontariopowergeneration.com * (416)592-4391

p5pRT commented 24 years ago

From [Unknown Contact. See original ticket]

If you think about it. It has to be a M$ bug. Why should perl care how many renames it has done or how many files there are in a directory.

I've recently had to rewrite some ftp code that I had been running. The file was transfered under a temproary name and then renamed to the final name. But depending upon the current configuration of stars\, a random number of files would not show up in the remote machine.

So using that tried and true debuggin mechanism I tried some voodoo programming and altered the algorithm to avoid the rename. Lo and behold no complaints in two months.

Isn't voodoo programming fantastic.

\

"DA-" == D'ANDREA Andy -NUCLEAR \andy\.d\.andrea@&#8203;ontariopowergeneration\.com writes​:

DA-> This is a bug report for perl from andy.d.andrea@​ontariopowergeneration.com\, DA-> generated with the help of perlbug 1.26 running under perl 5.00503.

DA-> The "rename oldname\, newname" function was being used to rename all files DA-> in a directory that were named in lowercase or a lower/uppercase mix to all DA-> uppercase.

DA-> The following code stops when the rename fails the first time. This code is DA-> being run on a networked NT 4 system. The problem occurs when running the DA-> script on a network directory containing about 20 files having lower case DA-> character in their names. It doesn't seem to be a problem if working on a DA-> local hard disk.

DA-> The file being worked on when rename fails is deleted from the filesystem!

DA-> Please let me know if fixed patch exists.

-- Chaim Frenkel Nonlinear Knowledge\, Inc. chaimf@​pobox.com +1-718-236-0183