Thursday, 9 August 2012

A tale of three paths...

This installment is entitled:

"A tale of three paths..."


Of course, we are not talking about an Oscar winning movie, rather our three paths simply are "~", "/", and "\\", the last one also known as @"\".
All of these three (path) characters play a signifcant role in our linux port.

Let's start with "~"


Changing .../umbraco/businesslogic/IO/IOHelpers.cs line 114: path[1] to path[0] got us going but it also introduced
a subtle bug. Here it is:

System.Exception
Could not locate TinyMCE by URI:/umbraco_client/tinymce3/tiny_mce_src.js, Physical path:/umbraco_client/tinymce3/tiny_mce_src.js. Make sure that you configured the installPath to a valid location in your web.config. This path should be an relative or site absolute URI to where TinyMCE is located.
.../umbraco/components/editorControls/tinyMCE3/webcontrol/TinyMCEWebControl.cs:219

Because we had effectively stripped the ~, the above was not mapped properly.

In fact going from path[1] to path[0] changes application behaviour significantly. As "~" in Linux is resolved as the value of $HOME, stripping the "~" character for any IO operation involving the file system makes sense. In windows, .NET operations which involve e.g. loading a file path with "~" in it resolve well. Not so under Linux.

Going from path[1] to path[0], however, did not work in this case:

Content > Trying to load a content page with a rich text editor
System.Exception
Could not locate TinyMCE by URI:/umbraco_client/tinymce3/tiny_mce_src.js, Physical path:/umbraco_client/tinymce3/tiny_mce_src.js. Make sure that you configured the installPath to a valid location in your web.config. This path should be an relative or site absolute URI to where TinyMCE is located.
.../umbraco/components/editorControls/tinyMCE3/webcontrol/TinyMCEWebControl.cs:219

So, now we apply a better fix

(1) In .../umbraco/businesslogic/IO, we have add a new MultiPlatformHelper class:
using System;
using System.Text;

namespace umbraco.IO
{
public static class MultiPlatformHelper
{

public const string PLATFORM_UNIX = "UNIX";
public const string PLATFORM_WIN = "WIN";

public const string WIN_DIRSEP = "\\";
public const string UNIX_DIRSEP = "/";

public static string OSPlatform
{
get
{
return System.Environment.OSVersion.Platform.ToString().ToUpper();
}
}

public static bool IsWindows()
{
return OSPlatform.Contains(PLATFORM_WIN);
}

public static bool IsUnix()
{
return OSPlatform.Contains(PLATFORM_UNIX);
}

public static string MapUnixPath(string path)
{
string filePath = path;

if (filePath.StartsWith("~"))
filePath = IOHelper.ResolveUrl(filePath);

filePath = IOHelper.MapPath(filePath, true);

return filePath;
}

public static string ConvertPathFromUnixToWin(string path)
{
return path.Replace(MultiPlatformHelper.UNIX_DIRSEP, MultiPlatformHelper.WIN_DIRSEP);
}

}
}

(2) Then in .../umbraco/businesslogic/IOHelper.cs, modify MapPath as:
        public static string MapPath(string path)

{

if (IO.MultiPlatformHelper.IsWindows())

return MapPath(path, true);

return IO.MultiPlatformHelper.MapUnixPath(path);

}

This fixes the tinyMCE load error and also makes the "~" path issues clear.

Again, this will keep us for now, but we will probably re-visit it in the future.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.