Skip to content

Commit

Permalink
[feature] experimental feature for temp drive
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveL-MSFT committed Jan 19, 2019
1 parent 631833c commit 9af3d10
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 12 deletions.
5 changes: 5 additions & 0 deletions src/System.Management.Automation/engine/DriveNames.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,10 @@ internal static class DriveNames
/// The default FunctionProvider drive name.
/// </summary>
internal const string FunctionDrive = "Function";

/// <summary>
/// The Temp drive name.
/// </summary>
internal const string TempDrive = "Temp";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,19 +83,27 @@ static ExperimentalFeature()
// Initialize the readonly collection 'EngineExperimentalFeatures'.
var engineFeatures = new ExperimentalFeature[] {
/* Register engine experimental features here. Follow the same pattern as the example:
new ExperimentalFeature(name: "PSFileSystemProviderV2",
description: "Replace the old FileSystemProvider with cleaner design and faster code",
source: EngineSource,
isEnabled: false),
new ExperimentalFeature(
name: "PSFileSystemProviderV2",
description: "Replace the old FileSystemProvider with cleaner design and faster code",
source: EngineSource,
isEnabled: false),
*/
new ExperimentalFeature(name: "PSImplicitRemotingBatching",
description: "Batch implicit remoting proxy commands to improve performance",
source: EngineSource,
isEnabled: false),
new ExperimentalFeature(name: "PSUseAbbreviationExpansion",
description: "Allow tab completion of cmdlets and functions by abbreviation",
source: EngineSource,
isEnabled: false),
new ExperimentalFeature(
name: "PSImplicitRemotingBatching",
description: "Batch implicit remoting proxy commands to improve performance",
source: EngineSource,
isEnabled: false),
new ExperimentalFeature(
name: "PSUseAbbreviationExpansion",
description: "Allow tab completion of cmdlets and functions by abbreviation",
source: EngineSource,
isEnabled: false),
new ExperimentalFeature(
name: "PSTempDrive",
description: "Create TEMP: PS Drive mapped to user's temporary directory path",
source: EngineSource,
isEnabled: false),
};
EngineExperimentalFeatures = new ReadOnlyCollection<ExperimentalFeature>(engineFeatures);

Expand Down
13 changes: 13 additions & 0 deletions src/System.Management.Automation/namespaces/FileSystemProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,6 +1000,19 @@ protected override Collection<PSDriveInfo> InitializeDefaultDrives()
}
}

if (ExperimentalFeature.IsEnabled("PSTempDrive"))
{
PSDriveInfo newPSDriveInfo =
new PSDriveInfo(
DriveNames.TempDrive,
ProviderInfo,
Path.GetTempPath(),
SessionStateStrings.TempDriveDescription,
credential: null,
displayRoot: null);
results.Add(newPSDriveInfo);
}

return results;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -624,6 +624,9 @@
<data name="VariableDriveDescription" xml:space="preserve">
<value>Drive that contains a view of those variables stored in a session state</value>
</data>
<data name="TempDriveDescription" xml:space="preserve">
<value>Drive that maps to the temporary directory path for the current user</value>
</data>
<data name="ProviderProviderPathFormatException" xml:space="preserve">
<value>The path is not in the correct format. Paths can contain only provider and drive names separated by slashes or backslashes.</value>
</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,27 @@ Describe "Get-PSDrive" -Tags "CI" {
$dInfo.Used -ge 0 | Should -BeTrue
}
}

Describe "Experimental Feature Temp: drive" -Tag Feature {
BeforeAll {
$configFilePath = Join-Path $testdrive "experimentalfeature.json"

@"
{
"ExperimentalFeatures": [
"PSTempDrive"
]
}
"@ > $configFilePath
}

It "TEMP: drive exists if experimental feature is enabled" {
$res = pwsh -outputformat xml -settingsfile $configFilePath -command "Get-PSDrive Temp"
$res.Name | Should -BeExactly "Temp"
$res.Root | Should -BeExactly ([System.IO.Path]::GetTempPath())
}

It "TEMP: drive does not exist if experimental feature is not enabled" {
{ Get-PSDrive Temp } | Should -Throw -ErrorId "GetLocationNoMatchingDrive,Microsoft.PowerShell.Commands.GetPSDriveCommand"
}
}

0 comments on commit 9af3d10

Please sign in to comment.