Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Re: Re: File::Copy dying on Win2k when target file already there

by John M. Dlugosz (Monsignor)
on Jan 17, 2003 at 02:30 UTC ( [id://227590]=note: print w/replies, xml ) Need Help??


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

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.

  • Comment on Re: Re: Re: File::Copy dying on Win2k when target file already there

Replies are listed 'Best First'.
Re: Re: Re: Re: File::Copy dying on Win2k when target file already there
by scain (Curate) on Jan 17, 2003 at 15:58 UTC
    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

      I guess the chmod on Windows is using the "word" write bit as the single read-only flag.

      You could conditionally note the value to use, once:

      use constant ROFLAG => $^O eq 'MSWin32' ? 0444 : 0644;
      and then use that constant in your code.

      I don't know what you mean about typing :w.

      —John

      First of all, in reply to John M. Dlugosz, please don't use eq: use constant ROFLAG => $^O =~ /win32/i ? 0444 : 0644;

      There is too much legacy code that does so already. If everyone used a regex $^O could be changed to contain more details about the exact version of Windows.

      However, this solution strikes me as an ugly hack anyway. How about this?

      chmod +(stat)[2] | 0444, $_ for $installfile;

      Makeshifts last the longest.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://227590]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (4)
As of 2024-06-24 01:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.