I got bitten by that today. I was working on a few programs that, in combination with make create a floppy disk to install a small Linux system on a specialized box. Part of the process involves copying executables to the root file system to be. Simple, isn't? Just do
use File::Copy; umask 022 or die "Failed to set umask: $!"; copy $src => $dest or die "Failed to copy: $!";
Well, that was what I did. Later, I needed to copy a directory structure. According to the manual page of File::Copy, that module just deals with copying files, so I shelled out:
system cp => '-a', $src, $dest; die "..." if $?;
But back to File::Copy and copy. The floppy disk was created, I insert it in the box, reboot, and after some time, it fails. /sbin/loader is not executable.
It turns out that File::Copy doesn't respect execution bits. Urg. Out went File::Copy and back came shelling out to the UNIX toolkit.
Here's a program that shows the unwanted behaviour of File::Copy:
#!/usr/bin/perl use strict; use warnings; use File::Copy; umask 022 or die "umask: $!"; my $one = "/tmp/one"; my $two = "/tmp/two"; my $three = "/tmp/three"; foreach my $file ($one, $two, $three) { ! -f $file or unlink $file or die "unlink $file: $!" } # Create first file. open my $fh, "> $one" or die "one: $!"; close $fh; # Make it executable. chmod 0755 => $one or die "chmod: $!"; # Copy it with File::Copy. copy $one, $two or die "copy: $!"; # Copy using the UNIX toolkit. system cp => $one, $three; die "cp: ", $? >> 8 if $?; # And check. print "$one is executable\n" if -x $one; print "$two is executable\n" if -x $two; print "$three is executable\n" if -x $three; __END__ /tmp/one is executable /tmp/three is executable
Abigail
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Pure Perl or the toolkit?
by arthas (Hermit) on Aug 20, 2003 at 14:33 UTC | |
Re: Pure Perl or the toolkit?
by dbwiz (Curate) on Aug 20, 2003 at 15:36 UTC | |
by halley (Prior) on Aug 20, 2003 at 19:42 UTC | |
by bronto (Priest) on Aug 21, 2003 at 07:22 UTC | |
by crouchingpenguin (Priest) on Aug 21, 2003 at 14:00 UTC | |
by Abigail-II (Bishop) on Aug 21, 2003 at 14:16 UTC | |
Re: Pure Perl or the toolkit?
by dragonchild (Archbishop) on Aug 20, 2003 at 14:30 UTC | |
Re: Pure Perl or the toolkit?
by chunlou (Curate) on Aug 20, 2003 at 19:02 UTC | |
by Anonymous Monk on Aug 20, 2003 at 20:58 UTC | |
Re: Pure Perl or the toolkit?
by liz (Monsignor) on Aug 20, 2003 at 15:18 UTC | |
Re: Pure Perl or the toolkit?
by bluto (Curate) on Aug 20, 2003 at 17:35 UTC | |
Re: Pure Perl or the toolkit?
by bm (Hermit) on Aug 21, 2003 at 10:17 UTC | |
Re: Pure Perl or the toolkit?
by crouchingpenguin (Priest) on Aug 21, 2003 at 13:24 UTC | |
by Abigail-II (Bishop) on Aug 21, 2003 at 13:44 UTC |