Expose file attributes of OneDrive placeholders (#8745)

This commit is contained in:
Stéphane BARIZIEN 2019-02-04 21:11:46 +01:00 committed by Andrew
parent 6e913c4318
commit d032cb2c87

View file

@ -341,7 +341,6 @@ namespace Microsoft.PowerShell.Commands
#endregion
#region CmdletProvider members
/// <summary>
/// Starts the File System provider. This method sets the Home for the
/// provider to providerInfo.Home if specified, and %USERPROFILE%
@ -373,6 +372,22 @@ namespace Microsoft.PowerShell.Commands
}
}
// OneDrive placeholder support (issue #8315)
// make it so OneDrive placeholders are perceived as such with *all* their attributes accessible
#if !UNIX
// The placeholder mode management APIs Rtl(Set|Query)(Process|Thread)PlaceholderCompatibilityMode
// are only supported starting with Windows 10 version 1803 (build 17134)
Version minBuildForPlaceHolderAPIs = new Version(10, 0, 17134, 0);
if (Environment.OSVersion.Version >= minBuildForPlaceHolderAPIs)
{
// let's be safe, don't change the PlaceHolderCompatibilityMode if the current one is not what we expect
if (NativeMethods.PHCM_DISGUISE_PLACEHOLDER == NativeMethods.RtlQueryProcessPlaceholderCompatibilityMode())
{
NativeMethods.RtlSetProcessPlaceholderCompatibilityMode(NativeMethods.PHCM_EXPOSE_PLACEHOLDERS);
}
}
#endif
return providerInfo;
}
@ -7061,6 +7076,31 @@ namespace Microsoft.PowerShell.Commands
Hidden = 0x0002,
Directory = 0x0010
}
// OneDrive placeholder support
#if !UNIX
/// <summary>
/// Returns the placeholder compatibility mode for the current process.
/// </summary>
/// <returns>The process's placeholder compatibily mode (PHCM_xxx), or a negative value on error (PCHM_ERROR_xxx).</returns>
[DllImport("ntdll.dll")]
internal static extern sbyte RtlQueryProcessPlaceholderCompatibilityMode();
/// <summary>
/// Sets the placeholder compatibility mode for the current process.
/// </summary>
/// <param name="pcm">The placeholder compatibility mode to set.</param>
/// <returns>The process's previous placeholder compatibily mode (PHCM_xxx), or a negative value on error (PCHM_ERROR_xxx).</returns>
[DllImport("ntdll.dll")]
internal static extern sbyte RtlSetProcessPlaceholderCompatibilityMode(sbyte pcm);
internal const sbyte PHCM_APPLICATION_DEFAULT = 0;
internal const sbyte PHCM_DISGUISE_PLACEHOLDER = 1;
internal const sbyte PHCM_EXPOSE_PLACEHOLDERS = 2;
internal const sbyte PHCM_MAX = 2;
internal const sbyte PHCM_ERROR_INVALID_PARAMETER = -1;
internal const sbyte PHCM_ERROR_NO_TEB = -2;
#endif
}
/// <summary>
@ -7466,8 +7506,10 @@ namespace Microsoft.PowerShell.Commands
/// Gets the status of the delimiter parameter. Returns true
/// if the delimiter was explicitly specified by the user, false otherwise.
/// </summary>
public bool DelimiterSpecified { get; private set;
// get
public bool DelimiterSpecified
{
get; private set;
// get
}
}
@ -7970,10 +8012,10 @@ namespace Microsoft.PowerShell.Commands
{
BY_HANDLE_FILE_INFORMATION infoOne;
BY_HANDLE_FILE_INFORMATION infoTwo;
if ( GetFileInformationByHandle(sfOne.DangerousGetHandle(), out infoOne)
if (GetFileInformationByHandle(sfOne.DangerousGetHandle(), out infoOne)
&& GetFileInformationByHandle(sfTwo.DangerousGetHandle(), out infoTwo))
{
return infoOne.VolumeSerialNumber == infoTwo.VolumeSerialNumber
return infoOne.VolumeSerialNumber == infoTwo.VolumeSerialNumber
&& infoOne.FileIndexHigh == infoTwo.FileIndexHigh
&& infoOne.FileIndexLow == infoTwo.FileIndexLow;
}