andrewrjones/grunt-ssh — pull request #34 by harriha (2013-10-20 21:29:36+00:00)
Title: Use stat() instead of opendir() for checking existence of a dir in sftpHelpers

Original problem: `opendir()` fails if given path doesn't have read permissions for
the current user (permissions 0xx).

I'm working with a hosted environment and can't naturally access the root folder. Since the helper function checks existence of directories starting from the root ('/') via trying to open each dir, using sftp with `createDirectories=true` failed for me. Using `stat()` instead of `opendir()` seems to solve the problem, to me it feels like a better way for checking whether a dir exists or not. However, please note that I'm not 100% sure if there were something else behind the way how this helper function is implemented, thus review & testing welcome.

To clarify, the failing scenario with current version can be created as follows:

* Create a sample dir:

```
$ pwd
/path/to/home
$ mkdir private
$ chmod ugo-rxw private/
```
* Try to sftp nested file structure to /path/to/home/private with `createDirectories=true`
* -> Operation will fail