Skip to content

Instantly share code, notes, and snippets.

@hesco
Created January 6, 2013 15:46
Show Gist options
  • Save hesco/4468021 to your computer and use it in GitHub Desktop.
Save hesco/4468021 to your computer and use it in GitHub Desktop.
With proper permissions, my code is unable to chdir; why?
This one has me stumped.
The user with which I am developing this owns that directory,
and in a bash shell, has no issues whatsoever changing to that
directory. Yet somehow (driven from my test script), my module
seems unwilling to make this change. And as a consequence, my
script is blowing up several lines later (thankfully) when it
attempts to overwrite the site I want to update with the updated
code.
package MyApp.pm;
use Cwd qw( getcwd abs_path );
use Log::Log4perl;
<snip>
sub install_site {
my $self = shift;
my $args = shift;
my $logger = get_logger('MyApp::install_site');
print "Now running ->install_site \n";
. . .
print Dumper( $args );
print Dumper( $args->{'doc_root'} );
my $doc_root = $args->{'doc_root'};
print "doc_root: $doc_root \n";
chdir $doc_root or warn "Unable to chdir to $doc_root \n";
my $abs_path = abs_path( '.' );
$logger->warn( "We've changed directory to: $abs_path " );
print "Our directory is: $abs_path \n";
. . .
return $app_id, $array_ref;
}
-----
t/013-this_test.t
my ($app_id, $array_ref) = $ymd_prov->install_site({
site_id => 75,
version => 6,
doc_root => 't/conf/var/www/sites/update.test.example.com/',
update => 1 });
-----
yields this output:
Now running ->install_site
$VAR1 = {
'version' => 6,
'site_id' => 75,
'update' => 1,
'doc_root' => 't/conf/var/www/sites/update.test.example.com/'
};
$VAR1 = 't/conf/var/www/sites/update.test.example.com/';
doc_root: t/conf/var/www/sites/update.test.example.com/
Unable to chdir to t/conf/var/www/sites/update.test.example.com/
Our directory is: /home/hesco/sandbox/MyApp/t/conf/var/www/sites/test.example.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment