sftp "cd" command to drive letter under cygwin

Peter Stuge peter at stuge.se
Wed Jan 9 04:35:50 EST 2013


Rick Patterson wrote:
> When using sftp under cygwin, a "cd d:" attempt to change to the d:
> drive, results in the following:
> sftp> cd d:/
> Couldn't canonicalise: No such file or directory.

Your quote is "cd d:" but your command is "cd d:/" and those are
different, so the above part is not very clear. Please clarify.


> Since cygwin is supposed to support DOS paths as well as UNIX
> paths, and the lcd is working, I thought I'd take a look at it.  I
> found the make_absolute function in sftp.c was assuming an absolute
> path starts with '/', but this is not true on Windows.   I think
> the attached sftp.c.diff file is the fix, for your review, although
> there is a behavior change I'd like to discuss below.

Why would a behavior change be acceptable? Any change that you make
must affect only Windows, and nothing else.


> Previously, under Cygwin, in sftp, "cd d:" would not work, unless
> there was a sub-directory in the current working directory that was
> named "d:", which is allowed on the UNIX file system,  as ":" is an
> allowed file name character.   With the proposed change, assuming
> you want to "cd to d:" (where d: is a drive specification, and
> therefore an absolute path),

Stop right here. "d:" is *NOT* an absolute path on Windows systems.

I'm sure you know that DOS and Windows both keep track of the current
working directory per drive. "d:" changes working drive, but does NOT
change current working directory either on the current driver or on d:.

"d:\" and "d:/" are absolute paths.


> the cd now works to the absolute path "d:" thereby supporting DOS
> paths.  However,  it also changes the previous behavior,  as "cd d:"
> will now not go to the sub-directory "d:" if it exists, unless it
> is qualified as "./d:"

I can not understand why you would modify behavior for every other
platform as well. Isn't it absolutely obvious that whatever change
you do in order to improve this on Windows must have *NO* effect on
the vast majority of other operating systems that OpenSSH supports?


> A "d:" needs to be treated firstly as an absolute path before a
> sub-directory.

On Cygwin, "d:" is a path relative to the current working directory
on drive d. Everywhere else, it is a path relative to the current
working directory.


> I agree a batter fix might be that "if d:" does not exist as a
> drive letter, but there is a "d:" sub-directory, then cd to the
> d: sub-directory.

Absolutely not, in my opinion. You are proposing to add a heuristic
into the user interface. Sorry, but that is just horrible.


> I've tested the cd command under the Cygwin command line shell - it
> does appear to be able to conditionally cd to d: as a DOS drive if
> it exists, ignoring  a d: sub-directory that exists.  However, if
> x: does not exist as a drive letter, but does exist as a
> sub-directory then it does cd to x:.   I believe an extra call from
> the sftp client to the sftp server would be required to do the
> conditional cd in sftp to be consistent with the Cygwin command
> line, but this would be beyond my abilities.

I'd suggest to look at the Cygwin source code to find out how exactly
chdir() is implemented, and to make sftp-server implement the same
algorithm. The client shouldn't have to be involved in this at all.
(Unless Cygwin patches all shells to make multiple chdir() calls, but
I find that somewhat unlikely.)


//Peter


More information about the openssh-unix-dev mailing list