Subject: | Unable to setcwd() to hidden directories (and fix) |
Hi Salvador,
first - many thanks for the wonderful module, it helps a lot!
I've got the following problem: sometimes a directory is hidden on a remote server. In my case the remote system is a mainframe, but another case would be the .snapshot directory of a netapp filer. In such cases a "cd .snapshot" would fail, because Net::SFTP::Foreign would call stat() on the directory. This doesn't work, since it's hidden.
So, I added a new flag to the setcwd() method: nostat => 1. If enabled, it just does the cwd without further checking. I've got to admit, that this could lead to problems though, if the said directory really doesn't exist. But it fixes the problem in my case.
best regards,
Tom
Subject: | setcwd-nostat.patch |
*** Foreign.pm.A Tue Apr 15 17:50:49 2014
--- Foreign.pm Tue Apr 15 18:00:04 2014
***************
*** 501,524 ****
}
sub setcwd {
! @_ <= 2 or croak 'Usage: $sftp->setcwd($path)';
${^TAINT} and &_catch_tainted_args;
! my ($sftp, $cwd) = @_;
$sftp->_clear_error_and_status;
if (defined $cwd) {
$cwd = $sftp->realpath($cwd);
return undef unless defined $cwd;
! my $a = $sftp->stat($cwd)
! or return undef;
! if (_is_dir($a->perm)) {
! return $sftp->{cwd} = $cwd;
}
else {
$sftp->_set_error(SFTP_ERR_REMOTE_BAD_OBJECT,
"Remote object '$cwd' is not a directory");
return undef;
}
}
else {
--- 501,532 ----
}
sub setcwd {
! @_ >= 1 or croak 'Usage: $sftp->setcwd($path)';
${^TAINT} and &_catch_tainted_args;
! my ($sftp, $cwd, %opts) = @_;
!
! my $nostat = delete $opts{nostat};
!
$sftp->_clear_error_and_status;
if (defined $cwd) {
$cwd = $sftp->realpath($cwd);
return undef unless defined $cwd;
! if ($nostat) {
! return $sftp->{cwd} = $cwd;
}
else {
+ my $a = $sftp->stat($cwd)
+ or return undef;
+ if (_is_dir($a->perm)) {
+ return $sftp->{cwd} = $cwd;
+ }
+ else {
$sftp->_set_error(SFTP_ERR_REMOTE_BAD_OBJECT,
"Remote object '$cwd' is not a directory");
return undef;
+ }
}
}
else {