Bug 40187

Summary: System.IO.Directory.CreateDirectory on Linux does not handle /.. in the path
Product: [Mono] Class Libraries Reporter: Kratzer Kevin <kratzer.kevin>
Component: SystemAssignee: Marek Safar <masafa>
Status: RESOLVED FIXED    
Severity: normal CC: masafa, mono-bugs+mono
Priority: ---    
Version: 4.2.0 (C6)   
Target Milestone: Untriaged   
Hardware: PC   
OS: Linux   
Tags: Is this bug a regression?: ---
Last known good build:
Attachments: Minimal Example Program

Description Kratzer Kevin 2016-04-07 07:41:36 UTC
Created attachment 15640 [details]
Minimal Example Program

Example:
Ensure /tmp/test does not exist. Run the following program:


using System.IO;
class MainClass
{
    public static void Main (string[] args)
    {
        var path = "/tmp/test/multifolder/relativepath/not_this_folder";
        path = Path.Combine (path, "..");
        Directory.CreateDirectory (path);
    }
}


Expected result (as seen on Windows with adjusted paths):
The folder /tmp/test/multifolder/relativepath/ has been created

Observed result:
The folder /tmp/test/multifolder has been created and the following exception is thrown:

System.IO.DirectoryNotFoundException: Could not find a part of the path "/tmp/test/multifolder/relativepath/not_this_folder/.."
  at System.IO.Directory.CreateDirectoriesInternal (System.String path) [0x0006b] in <filename unknown>:0
  at System.IO.Directory.CreateDirectory (System.String path) [0x000a4] in <filename unknown>:0
  at MainClass.Main (System.String[] args) [0x00014] in /home/kevin/Desktop/Test/TaskTEst/Program.cs:8

---------

> mono --version
Mono JIT compiler version 4.2.3 (Stable 4.2.3.4/832de4b Wed Mar 16 13:19:08 UTC 2016)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           __thread
	SIGSEGV:       altstack
	Notifications: epoll
	Architecture:  amd64
	Disabled:      none
	Misc:          softdebug 
	LLVM:          supported, not enabled.
	GC:            sgen

> cat /proc/version
Linux version 4.2.0-34-generic (buildd@lgw01-54) (gcc version 5.2.1 20151010 (Ubuntu 5.2.1-22ubuntu2) ) #39-Ubuntu SMP Thu Mar 10 22:13:01 UTC 2016


Xubuntu 15.10
Comment 1 Kratzer Kevin 2016-04-07 07:58:52 UTC
Addition: The same can be observed on Mac OS.
Comment 2 Marek Safar 2016-04-12 14:49:50 UTC
Fixed in master