Port NativeItemExists for Linux
Without using .NET
This commit is contained in:
parent
e89fa7b1dc
commit
5ef851a170
|
@ -416,6 +416,16 @@ namespace System.Management.Automation
|
|||
return hostName;
|
||||
}
|
||||
|
||||
internal static bool NonWindowsIsFile(string path)
|
||||
{
|
||||
return Unix.NativeMethods.IsFile(path);
|
||||
}
|
||||
|
||||
internal static bool NonWindowsIsDirectory(string path)
|
||||
{
|
||||
return Unix.NativeMethods.IsDirectory(path);
|
||||
}
|
||||
|
||||
internal static bool NonWindowsIsExecutable(string path)
|
||||
{
|
||||
return Unix.IsExecutable(path);
|
||||
|
@ -592,43 +602,12 @@ namespace System.Management.Automation
|
|||
|
||||
public static bool IsSymLink(FileSystemInfo fs)
|
||||
{
|
||||
if (!fs.Exists)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
string filePath = fs.FullName;
|
||||
int ret = NativeMethods.IsSymLink(filePath);
|
||||
switch(ret)
|
||||
{
|
||||
case 1:
|
||||
return true;
|
||||
case 0:
|
||||
return false;
|
||||
default:
|
||||
int lastError = Marshal.GetLastWin32Error();
|
||||
throw new InvalidOperationException("Unix.IsSymLink error: " + lastError);
|
||||
}
|
||||
return NativeMethods.IsSymLink(fs.FullName);
|
||||
}
|
||||
|
||||
public static bool IsExecutable(string filePath)
|
||||
{
|
||||
if (!File.Exists(filePath))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
int ret = NativeMethods.IsExecutable(filePath);
|
||||
switch(ret)
|
||||
{
|
||||
case 1:
|
||||
return true;
|
||||
case 0:
|
||||
return false;
|
||||
default:
|
||||
int lastError = Marshal.GetLastWin32Error();
|
||||
throw new InvalidOperationException("Unix.IsExecutable error: " + lastError);
|
||||
}
|
||||
return NativeMethods.IsExecutable(filePath);
|
||||
}
|
||||
|
||||
public static void SetDate(SetDateInfoInternal info)
|
||||
|
@ -739,6 +718,15 @@ namespace System.Management.Automation
|
|||
[DllImport(psLib, CharSet = CharSet.Ansi, SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.LPStr)]
|
||||
internal static extern string GetUserFromPid(int pid);
|
||||
|
||||
[DllImport(psLib, CharSet = CharSet.Ansi, SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.I1)]
|
||||
internal static extern bool IsFile([MarshalAs(UnmanagedType.LPStr)]string filePath);
|
||||
|
||||
[DllImport(psLib, CharSet = CharSet.Ansi, SetLastError = true)]
|
||||
[return: MarshalAs(UnmanagedType.I1)]
|
||||
internal static extern bool IsDirectory([MarshalAs(UnmanagedType.LPStr)]string filePath);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -995,6 +995,10 @@ namespace System.Management.Automation
|
|||
isDirectory = false;
|
||||
return false;
|
||||
}
|
||||
#if LINUX
|
||||
isDirectory = Platform.NonWindowsIsDirectory(path);
|
||||
return Platform.NonWindowsIsFile(path);
|
||||
#else
|
||||
|
||||
if (IsReservedDeviceName(path))
|
||||
{
|
||||
|
@ -1028,6 +1032,7 @@ namespace System.Management.Automation
|
|||
((int)NativeMethods.FileAttributes.Directory);
|
||||
|
||||
return true;
|
||||
#endif
|
||||
}
|
||||
|
||||
// This is done through P/Invoke since we pay 13% performance degradation
|
||||
|
|
Loading…
Reference in a new issue