in reply to File::Copy dying on Win2k when target file already there

Very strange. Your code is die "unable to copy to $installfile\n"; so where is it getting the " : invalid file descriptor" before the \n?

You might print $! and $^E also to find out why the copy failed.

One time when I had an "already there" problem, it's because the file was read-only. So you can't just delete it either. I unconditionally reset the attribute on the target, ignoring any error if it didn't exist, then did the copy.

—John

Replies are listed 'Best First'.
Re: Re: File::Copy dying on Win2k when target file already there
by scain (Curate) on Jan 16, 2003 at 21:24 UTC
    Very sorry about the confusion. I had a little bit of a versioning problem. I modified the error message line after I pasted in the code for the script to get a more informative error message, and forgot to fix the code. The modified line looks like this:
    copy($localfile, $installfile) or die "$localfile unable to copy to $installfile : $!\n";

    That said, demerphq helped me track down the problem. The problematic files where read-only, and apparently File::Copy won't let you copy over read-only files (even if you are the Administrator). I modified the code to add lines like this:

    fixreadonly($plugindir) if $^O =~ /win32/i; sub fixreadonly { my $dir = shift; my $unsetreadonly = Bio::Root::IO->catfile( $dir, "*.*"); system("attrib -r /s $unsetreadonly"); }

    Scott
    Project coordinator of the Generic Model Organism Database Project

      You can change the attribute using chmod, built into Perl, instead of calling out to system. I tried it using the UNIX bits meanings, and it did indeed turn off the R flag on Windows NT.

      That works the same on both platforms, so you don't even have to make it conditional.

        John,

        I did as you suggested and it works well. The readdir/while loop in the code above now looks like this:

        opendir PLUGINS, "conf/plugins" or die "unable to opendir ./conf/plugi +ns\n"; while (my $pluginfile = readdir(PLUGINS) ) { my $localfile = Bio::Root::IO->catfile('conf/plugins',$pluginfile) +; if (-f $localfile) { my $installfile = Bio::Root::IO->catfile($plugindir, $pluginfi +le); chmod (0666, $installfile); copy($localfile, $installfile) or die "$localfile unable to copy to $installfile : $!\n"; chmod (0444, $installfile); } } closedir PLUGINS;
        The only caveat being that I had to chmod the files to 444 (readonly by everyone, including the owner (root in this case)). It is fine for Windows, but an annoyance on unix. I would have preferred 644 (writeable by the owner), but on Windows, that is the same as world writeable (from Perl's chmod perspective).

        (I hate having to type :w and then :w! when I am reminded once again that the file is readonly.)

        Thanks,

        Scott
        Project coordinator of the Generic Model Organism Database Project