FileUtils::mkdir_p creates additional (unrequested) directory on Cygwin
FileUtils.mkdir(SOMEPATH) on Cygwin will create a directory ./c: in addition to SOMEPATH, if the following two conditions are met:
-SOMEPATH must be specified as absolute path using Windows drive letters and forward slashes as separators (so called "mixed-mode pathes" in Cygwin technologiy; see man cygpath).
- The parent directory of SOMEPATH does not exist.
The enclosed zip file demonstrates the problem. To run it, extract it to some directory, cd to this directory and then source the shell script file by typing
This script will create a directory c:/tmp, set up everything so that the error can become evident, and the runs mkdir_test.rb. This in turn creates a directory c:/tmp/foo/bar, and shows (using File.exist?), that in addition a director ./c: has been created. If you study the Ruby code, it will be obvious what's going wrong.
My guess is that at one point, FileUtils::mkdir needs to decide whether the path to be created is relative or absolute, and since c:/ is an absolute path only in the realm of Cygwin, but not in Unix, it creates a local directory ./c:. Note however that it does NOT create a full path ./c:/tmp/foo/bar. The requested directory is created as (in Windows notation) C:\TMP\FOO\BAR, as requested, and from this, I conclude, that mkdir_p is, by and large, Cygwin-aware. The error is not that the requested directory was not created, but that this mkdir_p call has created two directories, not one. Indeed, if I pass the path as
everything goes fine.
I can reproduce the error using the 64 Bit version of Cygwin. I don't know whether it also occurs in 32 Bit Cygwin.
Updated by nobu (Nobuyoshi Nakada) over 3 years ago
- Status changed from Open to Closed
Applied in changeset r57640.
fileutils.rb: do not make root
- lib/fileutils.rb (FileUtils#mkdir_p): no need to make root directory which should be exist and cannot be made with mkdir recent Cygwin can make a directory contains a colon. [Bug #13214]