Project

General

Profile

Actions

Bug #13214

closed

FileUtils::mkdir_p creates additional (unrequested) directory on Cygwin

Added by rovf (Ronald Fischer) about 7 years ago. Updated almost 7 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.2.5p319 (2016-04-26 revision 54774) [x86_64-cygwin]
[ruby-core:79529]

Description

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

. mkdir_test.shell

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

FileUtils.mkdir_p('/cygdrive/c/tmp/foo/bar')

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.


Files

mkdir_error_demo.zip (738 Bytes) mkdir_error_demo.zip rovf (Ronald Fischer), 02/14/2017 11:51 AM
Actions #1

Updated by nobu (Nobuyoshi Nakada) about 7 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]
Actions #2

Updated by usa (Usaku NAKAMURA) about 7 years ago

  • Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN to 2.2: REQUIRED, 2.3: REQUIRED, 2.4: REQUIRED

Updated by usa (Usaku NAKAMURA) about 7 years ago

  • Backport changed from 2.2: REQUIRED, 2.3: REQUIRED, 2.4: REQUIRED to 2.2: DONE, 2.3: REQUIRED, 2.4: REQUIRED

ruby_2_2 r58120 merged revision(s) 57640.

Updated by nagachika (Tomoyuki Chikanaga) about 7 years ago

  • Backport changed from 2.2: DONE, 2.3: REQUIRED, 2.4: REQUIRED to 2.2: DONE, 2.3: DONE, 2.4: REQUIRED

ruby_2_3 r58180 merged revision(s) 57640.

Updated by nagachika (Tomoyuki Chikanaga) almost 7 years ago

  • Backport changed from 2.2: DONE, 2.3: DONE, 2.4: REQUIRED to 2.2: DONE, 2.3: DONE, 2.4: DONE

ruby_2_4 r58631 merged revision(s) 57640.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0