You've already forked linux-packaging-mono
Imported Upstream version 5.0.0.42
Former-commit-id: fd56571888259555122d8a0f58c68838229cea2b
This commit is contained in:
parent
1190d13a04
commit
6bdd276d05
@@ -48,9 +48,16 @@ using System.Security.AccessControl;
|
||||
|
||||
namespace System.IO
|
||||
{
|
||||
[ComVisible (true)]
|
||||
public static class Directory
|
||||
public static partial class Directory
|
||||
{
|
||||
public static string GetDirectoryRoot (string path)
|
||||
{
|
||||
Path.Validate (path);
|
||||
SecurityManager.EnsureElevatedPermissions (); // this is a no-op outside moonlight
|
||||
|
||||
// FIXME nice hack but that does not work under windows
|
||||
return new String(Path.DirectorySeparatorChar, 1);
|
||||
}
|
||||
|
||||
public static DirectoryInfo CreateDirectory (string path)
|
||||
{
|
||||
@@ -251,77 +258,6 @@ namespace System.IO
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string [] GetDirectories (string path)
|
||||
{
|
||||
return GetDirectories (path, "*");
|
||||
}
|
||||
|
||||
public static string [] GetDirectories (string path, string searchPattern)
|
||||
{
|
||||
return GetFileSystemEntries (path, searchPattern, FileAttributes.Directory, FileAttributes.Directory);
|
||||
}
|
||||
|
||||
public static string [] GetDirectories (string path, string searchPattern, SearchOption searchOption)
|
||||
{
|
||||
if (searchOption == SearchOption.TopDirectoryOnly)
|
||||
return GetDirectories (path, searchPattern);
|
||||
var all = new List<string> ();
|
||||
GetDirectoriesRecurse (path, searchPattern, all);
|
||||
return all.ToArray ();
|
||||
}
|
||||
|
||||
static void GetDirectoriesRecurse (string path, string searchPattern, List<string> all)
|
||||
{
|
||||
all.AddRange (GetDirectories (path, searchPattern));
|
||||
foreach (string dir in GetDirectories (path))
|
||||
GetDirectoriesRecurse (dir, searchPattern, all);
|
||||
}
|
||||
|
||||
public static string GetDirectoryRoot (string path)
|
||||
{
|
||||
Path.Validate (path);
|
||||
SecurityManager.EnsureElevatedPermissions (); // this is a no-op outside moonlight
|
||||
|
||||
// FIXME nice hack but that does not work under windows
|
||||
return new String(Path.DirectorySeparatorChar,1);
|
||||
}
|
||||
|
||||
public static string [] GetFiles (string path)
|
||||
{
|
||||
return GetFiles (path, "*");
|
||||
}
|
||||
|
||||
public static string [] GetFiles (string path, string searchPattern)
|
||||
{
|
||||
return GetFileSystemEntries (path, searchPattern, FileAttributes.Directory, 0);
|
||||
}
|
||||
|
||||
public static string[] GetFiles (string path, string searchPattern, SearchOption searchOption)
|
||||
{
|
||||
if (searchOption == SearchOption.TopDirectoryOnly)
|
||||
return GetFiles (path, searchPattern);
|
||||
var all = new List<string> ();
|
||||
GetFilesRecurse (path, searchPattern, all);
|
||||
return all.ToArray ();
|
||||
}
|
||||
|
||||
static void GetFilesRecurse (string path, string searchPattern, List<string> all)
|
||||
{
|
||||
all.AddRange (GetFiles (path, searchPattern));
|
||||
foreach (string dir in GetDirectories (path))
|
||||
GetFilesRecurse (dir, searchPattern, all);
|
||||
}
|
||||
|
||||
public static string [] GetFileSystemEntries (string path)
|
||||
{
|
||||
return GetFileSystemEntries (path, "*");
|
||||
}
|
||||
|
||||
public static string [] GetFileSystemEntries (string path, string searchPattern)
|
||||
{
|
||||
return GetFileSystemEntries (path, searchPattern, 0, 0);
|
||||
}
|
||||
|
||||
public static string[] GetLogicalDrives ()
|
||||
{
|
||||
return Environment.GetLogicalDrives ();
|
||||
@@ -443,195 +379,6 @@ namespace System.IO
|
||||
SetLastWriteTime (path, lastWriteTimeUtc.ToLocalTime ());
|
||||
}
|
||||
|
||||
// private
|
||||
|
||||
// Does the common validation, searchPattern has already been checked for not-null
|
||||
static string ValidateDirectoryListing (string path, string searchPattern, out bool stop)
|
||||
{
|
||||
Path.Validate (path);
|
||||
|
||||
string wild = Path.Combine (path, searchPattern);
|
||||
string wildpath = Path.GetDirectoryName (wild);
|
||||
if (wildpath.IndexOfAny (Path.InvalidPathChars) != -1)
|
||||
throw new ArgumentException ("Pattern contains invalid characters", "pattern");
|
||||
|
||||
MonoIOError error;
|
||||
if (!MonoIO.ExistsDirectory (wildpath, out error)) {
|
||||
if (error == MonoIOError.ERROR_SUCCESS) {
|
||||
MonoIOError file_error;
|
||||
if (MonoIO.ExistsFile (wildpath, out file_error))
|
||||
throw new IOException ("The directory name is invalid.");
|
||||
}
|
||||
|
||||
if (error != MonoIOError.ERROR_PATH_NOT_FOUND)
|
||||
throw MonoIO.GetException (wildpath, error);
|
||||
|
||||
if (wildpath.IndexOfAny (SearchPattern.WildcardChars) == -1)
|
||||
throw new DirectoryNotFoundException ("Directory '" + wildpath + "' not found.");
|
||||
|
||||
if (path.IndexOfAny (SearchPattern.WildcardChars) == -1)
|
||||
throw new ArgumentException ("Pattern is invalid", "searchPattern");
|
||||
|
||||
throw new ArgumentException ("Path is invalid", "path");
|
||||
}
|
||||
|
||||
stop = false;
|
||||
return wild;
|
||||
}
|
||||
|
||||
private static string [] GetFileSystemEntries (string path, string searchPattern, FileAttributes mask, FileAttributes attrs)
|
||||
{
|
||||
if (searchPattern == null)
|
||||
throw new ArgumentNullException ("searchPattern");
|
||||
if (searchPattern.Length == 0)
|
||||
return new string [] {};
|
||||
bool stop;
|
||||
string path_with_pattern = ValidateDirectoryListing (path, searchPattern, out stop);
|
||||
if (stop)
|
||||
return new string [] { path_with_pattern };
|
||||
|
||||
MonoIOError error;
|
||||
string [] result = MonoIO.GetFileSystemEntries (path, path_with_pattern, (int) attrs, (int) mask, out error);
|
||||
if (error != 0)
|
||||
throw MonoIO.GetException (Path.GetDirectoryName (Path.Combine (path, searchPattern)), error);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public static string[] GetFileSystemEntries (string path, string searchPattern, SearchOption searchOption)
|
||||
{
|
||||
// Take the simple way home:
|
||||
return new List<string> (EnumerateFileSystemEntries (path, searchPattern, searchOption)).ToArray ();
|
||||
}
|
||||
|
||||
static void EnumerateCheck (string path, string searchPattern, SearchOption searchOption)
|
||||
{
|
||||
if (searchPattern == null)
|
||||
throw new ArgumentNullException ("searchPattern");
|
||||
|
||||
if (searchPattern.Length == 0)
|
||||
return;
|
||||
|
||||
if (searchOption != SearchOption.TopDirectoryOnly && searchOption != SearchOption.AllDirectories)
|
||||
throw new ArgumentOutOfRangeException ("searchoption");
|
||||
|
||||
Path.Validate (path);
|
||||
SecurityManager.EnsureElevatedPermissions (); // this is a no-op outside moonlight
|
||||
}
|
||||
|
||||
internal static IEnumerable<string> EnumerateKind (string path, string searchPattern, SearchOption searchOption, FileAttributes kind)
|
||||
{
|
||||
if (searchPattern.Length == 0)
|
||||
yield break;
|
||||
|
||||
bool stop;
|
||||
string path_with_pattern = ValidateDirectoryListing (path, searchPattern, out stop);
|
||||
if (stop){
|
||||
yield return path_with_pattern;
|
||||
yield break;
|
||||
}
|
||||
|
||||
IntPtr handle;
|
||||
MonoIOError error;
|
||||
FileAttributes rattr;
|
||||
string s = MonoIO.FindFirst (path, path_with_pattern, out rattr, out error, out handle);
|
||||
try {
|
||||
while (s != null) {
|
||||
// Convert any file specific flag to FileAttributes.Normal which is used as include files flag
|
||||
if (((rattr & FileAttributes.Directory) == 0) && rattr != 0)
|
||||
rattr |= FileAttributes.Normal;
|
||||
|
||||
if ((rattr & kind) != 0)
|
||||
yield return s;
|
||||
|
||||
s = MonoIO.FindNext (handle, out rattr, out error);
|
||||
}
|
||||
|
||||
if (error != 0)
|
||||
throw MonoIO.GetException (Path.GetDirectoryName (Path.Combine (path, searchPattern)), (MonoIOError) error);
|
||||
} finally {
|
||||
if (handle != IntPtr.Zero)
|
||||
MonoIO.FindClose (handle);
|
||||
}
|
||||
|
||||
if (searchOption == SearchOption.AllDirectories) {
|
||||
s = MonoIO.FindFirst (path, Path.Combine (path, "*"), out rattr, out error, out handle);
|
||||
|
||||
try {
|
||||
while (s != null) {
|
||||
if ((rattr & FileAttributes.Directory) != 0 && (rattr & FileAttributes.ReparsePoint) == 0)
|
||||
foreach (string child in EnumerateKind (s, searchPattern, searchOption, kind))
|
||||
yield return child;
|
||||
s = MonoIO.FindNext (handle, out rattr, out error);
|
||||
}
|
||||
|
||||
if (error != 0)
|
||||
throw MonoIO.GetException (path, (MonoIOError) error);
|
||||
} finally {
|
||||
if (handle != IntPtr.Zero)
|
||||
MonoIO.FindClose (handle);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static IEnumerable<string> EnumerateDirectories (string path, string searchPattern, SearchOption searchOption)
|
||||
{
|
||||
EnumerateCheck (path, searchPattern, searchOption);
|
||||
return EnumerateKind (path, searchPattern, searchOption, FileAttributes.Directory);
|
||||
}
|
||||
|
||||
public static IEnumerable<string> EnumerateDirectories (string path, string searchPattern)
|
||||
{
|
||||
EnumerateCheck (path, searchPattern, SearchOption.TopDirectoryOnly);
|
||||
return EnumerateKind (path, searchPattern, SearchOption.TopDirectoryOnly, FileAttributes.Directory);
|
||||
}
|
||||
|
||||
public static IEnumerable<string> EnumerateDirectories (string path)
|
||||
{
|
||||
Path.Validate (path); // no need for EnumerateCheck since we supply valid arguments
|
||||
SecurityManager.EnsureElevatedPermissions (); // this is a no-op outside moonlight
|
||||
return EnumerateKind (path, "*", SearchOption.TopDirectoryOnly, FileAttributes.Directory);
|
||||
}
|
||||
|
||||
public static IEnumerable<string> EnumerateFiles (string path, string searchPattern, SearchOption searchOption)
|
||||
{
|
||||
EnumerateCheck (path, searchPattern, searchOption);
|
||||
return EnumerateKind (path, searchPattern, searchOption, FileAttributes.Normal);
|
||||
}
|
||||
|
||||
public static IEnumerable<string> EnumerateFiles (string path, string searchPattern)
|
||||
{
|
||||
EnumerateCheck (path, searchPattern, SearchOption.TopDirectoryOnly);
|
||||
return EnumerateKind (path, searchPattern, SearchOption.TopDirectoryOnly, FileAttributes.Normal);
|
||||
}
|
||||
|
||||
public static IEnumerable<string> EnumerateFiles (string path)
|
||||
{
|
||||
Path.Validate (path); // no need for EnumerateCheck since we supply valid arguments
|
||||
SecurityManager.EnsureElevatedPermissions (); // this is a no-op outside moonlight
|
||||
return EnumerateKind (path, "*", SearchOption.TopDirectoryOnly, FileAttributes.Normal);
|
||||
}
|
||||
|
||||
public static IEnumerable<string> EnumerateFileSystemEntries (string path, string searchPattern, SearchOption searchOption)
|
||||
{
|
||||
EnumerateCheck (path, searchPattern, searchOption);
|
||||
return EnumerateKind (path, searchPattern, searchOption, FileAttributes.Normal | FileAttributes.Directory);
|
||||
}
|
||||
|
||||
public static IEnumerable<string> EnumerateFileSystemEntries (string path, string searchPattern)
|
||||
{
|
||||
EnumerateCheck (path, searchPattern, SearchOption.TopDirectoryOnly);
|
||||
return EnumerateKind (path, searchPattern, SearchOption.TopDirectoryOnly, FileAttributes.Normal | FileAttributes.Directory);
|
||||
}
|
||||
|
||||
public static IEnumerable<string> EnumerateFileSystemEntries (string path)
|
||||
{
|
||||
Path.Validate (path); // no need for EnumerateCheck since we supply valid arguments
|
||||
SecurityManager.EnsureElevatedPermissions (); // this is a no-op outside moonlight
|
||||
return EnumerateKind (path, "*", SearchOption.TopDirectoryOnly, FileAttributes.Normal | FileAttributes.Directory);
|
||||
}
|
||||
|
||||
|
||||
public static DirectorySecurity GetAccessControl (string path, AccessControlSections includeSections)
|
||||
{
|
||||
return new DirectorySecurity (path, includeSections);
|
||||
|
Reference in New Issue
Block a user