public static bool CheckAccess(string filename, CheckAccessMode mode, CheckAccessOptions options)
{
Debug.Assert(Path.IsPathRooted(filename));
string url = FileSystemUtils.StripPassword(filename);
bool quiet = (options & CheckAccessOptions.Quiet) > 0;
switch (mode)
{
case CheckAccessMode.FileMayExist:
break;
case CheckAccessMode.FileExists:
if (!File.Exists(filename))
{
if (!quiet) PhpException.Throw(PhpError.Warning, ErrResources.stream_file_not_exists, url);
return false;
}
break;
case CheckAccessMode.FileNotExists:
if (File.Exists(filename))
{
if (!quiet) PhpException.Throw(PhpError.Warning, ErrResources.stream_file_exists, url);
return false;
}
break;
case CheckAccessMode.FileOrDirectory:
if ((!Directory.Exists(filename)) && (!File.Exists(filename)))
{
if (!quiet) PhpException.Throw(PhpError.Warning, ErrResources.stream_path_not_exists, url);
return false;
}
break;
case CheckAccessMode.Directory:
if (!Directory.Exists(filename))
{
if (!quiet) PhpException.Throw(PhpError.Warning, ErrResources.stream_directory_not_exists, url);
return false;
}
break;
default:
Debug.Assert(false);
return false;
}
return true;
}