Bug Report: Path.GetDirectoryName incorrectly removes "//" from the start of paths.


(Stephen Foster) #1

Hi,

While integrating the new version of FMOD (1.07 Unity Integration 2), I found that FMOD settings would not detect the builds folder over the network (separate hostname), yet would detect the actual project file no problem.

After investigation, we have found that mono’s implementation of the Path.GetDirectoryName function does not preserve ‘//’ on the start of paths. Therefore losing the hostname from the path and failing detection of the builds folder.

i.e. (the following is inclusive of escape characters): ‘//’ becomes ‘\\’ when it should become ‘\\\\’. The reason ‘//’ becomes ‘\\’ is because mono tries to remove duplicate delimiters.

I have temporarily fixed this in the two relevant places with the code:

	if (projectPath.StartsWith("//"))
	{
		projectFolder = "\\" + projectFolder;
	}

For reference, the places affected by this issue are both in EditorUtils.cs. Lines 30 and 61.

Kind Regards,
Steve


(Brett Paterson) #2

Thanks Steve we’ll look into this for the next release.


(Nicholas Wilcox) #3

Can I clarify what platform this is on? Windows UNC paths must start with ‘\\’. Other separators can be forward of back slashes.


(Stephen Foster) #4

Sorry, this occurred on Windows.

Kind Regards,
Steve


(Nicholas Wilcox) #5

I think the solution is to use the correct UNC path starting with ‘\\’ rather than changing the code to silently fix incorrect input.


(Stephen Foster) #6

This makes the assumption that you’re not working with cross platform paths. The fact is that Mono’s implementation of the Path.GetDirectoryName is incorrect. A bit of googling shows that the source actually is incorrect, and the .NET framework’s implementation of this function has a specific line of code (which is even commented) which works around this issue.

Path.GetDirectoryName should return you the correct path regardless of the delimiter used in the input path, therefore using “//” as opposed to “\” is not incorrect input.

Kind Regards,
Steve


(Stephen Foster) #7

Furthermore, it is not the user’s code that sets the path and delimiter. The event paths generated by FMOD use forward slash in their paths regardless of the platform.

Kind Regards,
Steve


(Nicholas Wilcox) #8

If I use the directory selector on Windows it give me the correct UNC paths.