Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -942,6 +942,7 @@ protected override void NewItem(
StoreLocation.LocalMachine);
WriteItemObject(outStore, path, true);
}

#region DriveCmdletProvider overrides

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,16 @@ public override string ToString()
/// </summary>
public bool VolumeSeparatedByColon { get; internal set; } = true;

/// <summary>
/// Gets the default item separator character for this provider.
/// </summary>
public char ItemSeparator { get; private set; }

/// <summary>
/// Gets the alternate item separator character for this provider.
/// </summary>
public char AltItemSeparator { get; private set; }

/// <summary>
/// Constructs an instance of the class using an existing reference
/// as a template.
Expand Down Expand Up @@ -292,6 +302,8 @@ protected ProviderInfo(ProviderInfo providerInfo)
PSSnapIn = providerInfo.PSSnapIn;
_sessionState = providerInfo._sessionState;
VolumeSeparatedByColon = providerInfo.VolumeSeparatedByColon;
ItemSeparator = providerInfo.ItemSeparator;
AltItemSeparator = providerInfo.AltItemSeparator;
}

/// <summary>
Expand Down Expand Up @@ -606,6 +618,8 @@ internal Provider.CmdletProvider CreateInstance()
}

Provider.CmdletProvider result = providerInstance as Provider.CmdletProvider;
ItemSeparator = result.ItemSeparator;
AltItemSeparator = result.AltItemSeparator;

Dbg.Diagnostics.Assert(
result != null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ internal override bool CanRenameItem(object item)

return result;
}

#endregion protected members

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,9 @@ public string GetHelpMaml(string helpItemName, string path)
#endregion

#region CmdletProvider members

/// <summary>
/// Starts the File System provider. This method sets the Home for the
/// Starts the File System provider. This method sets the Home for the
/// provider to providerInfo.Home if specified, and %USERPROFILE%
/// otherwise.
/// </summary>
Expand All @@ -354,7 +355,7 @@ public string GetHelpMaml(string helpItemName, string path)
protected override ProviderInfo Start(ProviderInfo providerInfo)
{
// Set the home folder for the user
if (providerInfo != null && string.IsNullOrEmpty(providerInfo.Home))
if (providerInfo != null && string.IsNullOrEmpty(providerInfo.Home))
{
// %USERPROFILE% - indicate where a user's home directory is located in the file system.
string homeDirectory = Environment.GetEnvironmentVariable(Platform.CommonEnvVariableNames.Home);
Expand Down
16 changes: 16 additions & 0 deletions src/System.Management.Automation/namespaces/ProviderBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#pragma warning disable 56506

using System.Collections.ObjectModel;
using System.IO;
using System.Management.Automation.Runspaces;
using System.Management.Automation.Internal;
using System.Management.Automation.Host;
Expand Down Expand Up @@ -1384,6 +1385,21 @@ public PSHost Host
}
}

/// <summary>
/// Gets the default item separator character for this provider.
/// </summary>
public virtual char ItemSeparator => Path.DirectorySeparatorChar;

/// <summary>
/// Gets the alternate item separator character for this provider.
/// </summary>
public virtual char AltItemSeparator =>
#if UNIX
Utils.Separators.Backslash[0];
#else
Path.AltDirectorySeparatorChar;
#endif

#region IResourceSupplier
/// <summary>
/// Gets the resource string corresponding to baseName and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,15 @@ public sealed partial class RegistryProvider :
/// </summary>
public const string ProviderName = "Registry";

#region CmdletProvider overrides

/// <summary>
/// Gets the alternate item separator character for this provider.
/// </summary>
public override char AltItemSeparator => ItemSeparator;

#endregion

#region DriveCmdletProvider overrides

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,43 @@ Describe "Get-PSProvider" -Tags "CI" {

{ $actual | Format-List } | Should -Not -Throw
}

Context 'ItemSeparator properties' {
BeforeAll {
$testCases = if ($IsWindows) {
@(
@{Provider = 'FileSystem'; ItemSeparator = '\'; AltItemSeparator = '/'}
@{Provider = 'Variable'; ItemSeparator = '\'; AltItemSeparator = '/'}
@{Provider = 'Function'; ItemSeparator = '\'; AltItemSeparator = '/'}
@{Provider = 'Alias'; ItemSeparator = '\'; AltItemSeparator = '/'}
@{Provider = 'Environment'; ItemSeparator = '\'; AltItemSeparator = '/'}
@{Provider = 'Certificate'; ItemSeparator = '\'; AltItemSeparator = '/'}
@{Provider = 'Registry'; ItemSeparator = '\'; AltItemSeparator = '\'}
)
}
else {
@(
@{Provider = 'FileSystem'; ItemSeparator = '/'; AltItemSeparator = '\'}
@{Provider = 'Variable'; ItemSeparator = '/'; AltItemSeparator = '\'}
@{Provider = 'Function'; ItemSeparator = '/'; AltItemSeparator = '\'}
@{Provider = 'Alias'; ItemSeparator = '/'; AltItemSeparator = '\'}
@{Provider = 'Environment'; ItemSeparator = '/'; AltItemSeparator = '\'}
)
}
}

It '<Provider> provider has ItemSeparator properties' -TestCases $testCases {
param ($Provider, $ItemSeparator, $AltItemSeparator)

(Get-PSProvider $Provider).ItemSeparator | Should -Be $ItemSeparator
(Get-PSProvider $Provider).AltItemSeparator | Should -Be $AltItemSeparator
}

It 'ItemSeparator properties is read-only in <Provider> provider' -TestCases $testCases {
param ($Provider, $ItemSeparator, $AltItemSeparator)

{ (Get-PSProvider $Provider).ItemSeparator = $null } | Should -Throw
{ (Get-PSProvider $Provider).AltItemSeparator = $null } | Should -Throw
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -439,4 +439,17 @@ Describe "WSMan Config Provider" -Tag Feature,RequireAdminOnWindows {
}
}
}

Context 'ItemSeparator properties' {
It 'WSMan provider has ItemSeparator properties' {

(Get-PSProvider WSMan).ItemSeparator | Should -Be '\'
(Get-PSProvider WSMan).AltItemSeparator | Should -Be '/'
}

It 'ItemSeparator properties is read-only in WSMan provider' {
{ (Get-PSProvider WSMan).ItemSeparator = $null } | Should -Throw
{ (Get-PSProvider WSMan).AltItemSeparator = $null } | Should -Throw
}
}
}