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
In reply to Pure Perl or the toolkit? by Abigail-II
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |