On May 21, 2006, at 7:29 PM, James E Keenan wrote:
Let's say that I'm writing a test suite for a Perl module which
creates files and then, optionally, moves those files to
predetermined directories. To test this module's functionality, I
would have to see what happens when the user running the tests does
not have write permissions on the destination directory (e.g., test
whether an appropriate warning was issued). But to do *that*, I
would have to change permissions on a directory to forbid myself to
write to it.
This code is intended to achieve that goal but doesn't DWIM:
my ($file, $workdir, $destdir);
{
$workdir = File::Temp::tempdir();
chdir $workdir or die "Cannot change to $workdir";
$file = system("touch alpha");
$destdir = "$workdir/other";
chmod 0330, ($destdir)
or die "Cannot change permissions on directory";
# dies on preceding line
rename $file, $destdir/$file or die "Cannot move $file";
}
Is there any other way to do this? Or am I mistaken in even
attempting to try it? Thanks.
Jim Keenan
use strict;
use warnings;
use File::Temp;
my ($file, $workdir, $destdir);
{
$workdir = File::Temp::tempdir();
chdir $workdir or die "Cannot change to $workdir";
$file = system("touch alpha");
$destdir = "$workdir/other";
if ( ! -d $destdir ) {
die "Directory '$destdir' missing!";
}
chmod 0330, $destdir
or die "Cannot change permissions on directory";
# dies on preceding line
rename $file, $destdir/$file or die "Cannot move $file";
}
gives:
# perl /tmp/perms.pl
Directory '/tmp/xljbEqunk1/other' missing! at /tmp/perms.pl line 11.