public override bool MakeDirectory(string path, int accessMode, StreamMakeDirectoryOptions options, StreamContext context)
{
if ((path == null) || (path == string.Empty))
{
PhpException.Throw(PhpError.Warning, ErrResources.path_argument_empty);
return false;
}
try
{
// Default Framework MakeDirectory is RECURSIVE, check for other intention.
if ((options & StreamMakeDirectoryOptions.Recursive) == 0)
{
int pos = path.Length - 1;
if (path[pos] == Path.DirectorySeparatorChar) pos--;
pos = path.LastIndexOf(Path.DirectorySeparatorChar, pos);
if (pos <= 0)
{
PhpException.Throw(PhpError.Warning, ErrResources.stream_directory_make_root, FileSystemUtils.StripPassword(path));
return false;
}
// Parent must exist if not recursive.
string parent = path.Substring(0, pos);
if (!Directory.Exists(parent))
{
PhpException.Throw(PhpError.Warning, ErrResources.stream_directory_make_parent, FileSystemUtils.StripPassword(path));
return false;
}
}
// Creates the whole path
Directory.CreateDirectory(path);
return true;
}
catch (UnauthorizedAccessException)
{
// The caller does not have the required permission.
PhpException.Throw(PhpError.Warning, ErrResources.stream_directory_access_denied, FileSystemUtils.StripPassword(path));
}
catch (IOException)
{
// The directory specified by path is read-only or is not empty.
PhpException.Throw(PhpError.Warning, ErrResources.stream_directory_error, FileSystemUtils.StripPassword(path));
}
catch (System.Exception e)
{
// The specified path is invalid, such as being on an unmapped drive ...
PhpException.Throw(PhpError.Warning, ErrResources.stream_error, FileSystemUtils.StripPassword(path), e.Message);
}
return false;
}