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

Re: Pure Perl or the toolkit?

by dbwiz (Curate)
on Aug 20, 2003 at 15:36 UTC ( [id://285221]=note: print w/replies, xml ) Need Help??


in reply to Pure Perl or the toolkit?

So File::Copy does not preserve the attributes of the copied file. Can't we fix it?

package NewCopy; use strict; use warnings; use File::Copy; require Exporter; our @ISA = qw(File::Copy); our @EXPORT = qw(copy move); our @EXPORT_OK = qw(cp mv); sub cp; sub mv; *cp = \© *mv = \&move; no warnings; eval { sub copy{ my ($attr) = (stat( $_[0] ))[2] or return -1; return (File::Copy::copy(@_) && (chmod ($attr, $_[1]) ); } sub move { return File::Copy::move(@_) } }; 1;

Replace "use File::Copy" with "use NewCopy" in your script and it will give

/tmp/one is executable /tmp/two is executable /tmp/three is executable

Replies are listed 'Best First'.
Re: Re: Pure Perl or the toolkit?
by halley (Prior) on Aug 20, 2003 at 19:42 UTC
    So File::Copy does not preserve the attributes of the copied file. Can't we fix it?

    This is a band-aid that more closely approximates the desired behavior, but it will always be a chasing game of approximation (until the Unix/Linux systems provide a basic syscopy feature).

    Say you implement this. Then you want to copy files which have ACLs (Access Control Lists) attached. Now you have to fix File::Copy again to copy the ACLs too. Tomorrow, what other file metadata will be employed at the filesystem level?

    --
    [ e d @ h a l l e y . c c ]

      Say you implement this. Then you want to copy files which have ACLs (Access Control Lists) attached. Now you have to fix File::Copy again to copy the ACLs too. Tomorrow, what other file metadata will be employed at the filesystem level?

      IMHO, it doesn't make sense to worry about tomorrow problems if you don't know what they will be (well, at least with a fair amount of probability). <AFAIK>ACLsare still different from OS to OS, and somewhere they can be considered experimental;</AFAIK> it is a moving target, that one can plan to address only where it is stable enough.

      By the way, UNIX file permissions are there from the start, on every flavour of UNIX, and that problem on File::Copy should be addressed...

      Ciao!
      --bronto


      The very nature of Perl to be like natural language--inconsistant and full of dwim and special cases--makes it impossible to know it all without simply memorizing the documentation (which is not complete or totally correct anyway).
      --John M. Dlugosz

        ...it doesn't make sense to worry about tomorrow problems if you don't know what they will be...

        See You aren't gonna need it for a bit more on exactly that.


        cp
        ----
        "Never be afraid to try something new. Remember, amateurs built the ark. Professionals built the Titanic."
Re: Pure Perl or the toolkit?
by Abigail-II (Bishop) on Aug 21, 2003 at 14:16 UTC
    And after that, we will make a NewerCopy.pm that also take umask into consideration (which is what cp does)? And after that, we make a EverNewerCopy which supports the -p option?

    My point wasn't that File::Copy needs fixing. My point is that the choice between shelling out to do something and using a Perl solution isn't as simple as it is sometimes suggested, and that people should be trigger happy and reply "Why don't you use Perl for that" if someone shows code where shell commands are being used.

    Abigail

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2024-04-18 20:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found