diff --git a/help/Install-PSResource.md b/help/Install-PSResource.md index 28eb45d6f..eb12f1aae 100644 --- a/help/Install-PSResource.md +++ b/help/Install-PSResource.md @@ -17,7 +17,7 @@ Installs resources from a registered repository. ``` Install-PSResource [-Name] [-Version ] [-Prerelease] [-Repository ] - [-Credential ] [-Scope ] [-TrustRepository] [-Reinstall] [-Quiet] + [-Credential ] [-Scope ] [-TemporaryPath ] [-TrustRepository] [-Reinstall] [-Quiet] [-AcceptLicense] [-NoClobber] [-SkipDependencyCheck] [-AuthenticodeCheck] [-PassThru] [-WhatIf] [-Confirm] [] ``` @@ -224,6 +224,22 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -TemporaryPath + +Specifies the path to temporarily install the resource before actual installation. If no temporary path is provided, the resource is temporarily installed in the current user's temporary folder. + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -Prerelease When specified, includes prerelease versions in search results returned. diff --git a/help/Save-PSResource.md b/help/Save-PSResource.md index 2029fb6d4..e98cf87b3 100644 --- a/help/Save-PSResource.md +++ b/help/Save-PSResource.md @@ -17,7 +17,7 @@ Saves resources (modules and scripts) from a registered repository onto the mach ``` Save-PSResource [-Name] [-Version ] [-Prerelease] [-Repository ] - [-Credential ] [-AsNupkg] [-IncludeXML] [-Path ] [-TrustRepository] + [-Credential ] [-AsNupkg] [-IncludeXML] [-Path ] [-TemporaryPath ] [-TrustRepository] [-PassThru] [-SkipDependencyCheck] [-AuthenticodeCheck] [-Quiet] [-WhatIf] [-Confirm] [] ``` @@ -207,6 +207,22 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -TemporaryPath + +Specifies the path to temporarily install the resource before saving. If no temporary path is provided, the resource is temporarily installed in the current user's temporary folder. + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -Prerelease When specified, includes prerelease versions in search results returned. diff --git a/help/Update-PSResource.md b/help/Update-PSResource.md index bdfa732ad..d527d3611 100644 --- a/help/Update-PSResource.md +++ b/help/Update-PSResource.md @@ -17,7 +17,7 @@ Downloads and installs the newest version of a package already installed on the ``` Update-PSResource [[-Name] ] [-Version ] [-Prerelease] [-Repository ] - [-Scope ] [-TrustRepository] [-Credential ] [-Quiet] [-AcceptLicense] + [-Scope ] [-TemporaryPath ] [-TrustRepository] [-Credential ] [-Quiet] [-AcceptLicense] [-Force] [-PassThru] [-SkipDependencyCheck] [-AuthenticodeCheck] [-WhatIf] [-Confirm] [] ``` @@ -162,6 +162,22 @@ Accept pipeline input: False Accept wildcard characters: False ``` +### -TemporaryPath + +Specifies the path to temporarily install the resource before actual installatoin. If no temporary path is provided, the resource is temporarily installed in the current user's temporary folder. + +```yaml +Type: System.String +Parameter Sets: (All) +Aliases: + +Required: False +Position: Named +Default value: None +Accept pipeline input: False +Accept wildcard characters: False +``` + ### -Prerelease When specified, allows updating to a prerelease version. diff --git a/src/code/InstallHelper.cs b/src/code/InstallHelper.cs index 75f6d54f2..dfa0c66cb 100644 --- a/src/code/InstallHelper.cs +++ b/src/code/InstallHelper.cs @@ -53,6 +53,7 @@ internal class InstallHelper : PSCmdlet private bool _savePkg; List _pathsToSearch; List _pkgNamesToInstall; + private string _tmpPath; #endregion @@ -82,10 +83,11 @@ public List InstallPackages( bool skipDependencyCheck, bool authenticodeCheck, bool savePkg, - List pathsToInstallPkg) + List pathsToInstallPkg, + string tmpPath) { _cmdletPassedIn.WriteVerbose(string.Format("Parameters passed in >>> Name: '{0}'; Version: '{1}'; Prerelease: '{2}'; Repository: '{3}'; " + - "AcceptLicense: '{4}'; Quiet: '{5}'; Reinstall: '{6}'; TrustRepository: '{7}'; NoClobber: '{8}'; AsNupkg: '{9}'; IncludeXml '{10}'; SavePackage '{11}'", + "AcceptLicense: '{4}'; Quiet: '{5}'; Reinstall: '{6}'; TrustRepository: '{7}'; NoClobber: '{8}'; AsNupkg: '{9}'; IncludeXml '{10}'; SavePackage '{11}'; TemporaryPath '{12}'", string.Join(",", names), versionRange != null ? (versionRange.OriginalString != null ? versionRange.OriginalString : string.Empty) : string.Empty, prerelease.ToString(), @@ -97,7 +99,9 @@ public List InstallPackages( noClobber.ToString(), asNupkg.ToString(), includeXml.ToString(), - savePkg.ToString())); + savePkg.ToString(), + tmpPath ?? string.Empty)); + _versionRange = versionRange; _prerelease = prerelease; @@ -113,6 +117,7 @@ public List InstallPackages( _includeXml = includeXml; _savePkg = savePkg; _pathsToInstallPkg = pathsToInstallPkg; + _tmpPath = tmpPath ?? Path.GetTempPath(); // Create list of installation paths to search. _pathsToSearch = new List(); @@ -327,7 +332,7 @@ private List InstallPackage( foreach (PSResourceInfo pkg in pkgsToInstall) { currentInstalledPkgCount++; - var tempInstallPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString()); + var tempInstallPath = Path.Combine(_tmpPath, Guid.NewGuid().ToString()); try { // Create a temp directory to install to diff --git a/src/code/InstallPSResource.cs b/src/code/InstallPSResource.cs index 4149a2ba5..b27b48093 100644 --- a/src/code/InstallPSResource.cs +++ b/src/code/InstallPSResource.cs @@ -67,6 +67,29 @@ class InstallPSResource : PSCmdlet [Parameter] public ScopeType Scope { get; set; } + /// + /// The destination where the resource is to be temporarily installed + /// + [Parameter] + [ValidateNotNullOrEmpty] + public string TemporaryPath + { + get + { return _tmpPath; } + + set + { + if (WildcardPattern.ContainsWildcardCharacters(value)) + { + throw new PSArgumentException("Wildcard characters are not allowed in the temporary path."); + } + + // This will throw if path cannot be resolved + _tmpPath = SessionState.Path.GetResolvedPSPathFromPSPath(value).First().Path; + } + } + private string _tmpPath; + /// /// Suppresses being prompted for untrusted sources. /// @@ -528,7 +551,8 @@ private void ProcessInstallHelper(string[] pkgNames, VersionRange pkgVersion, bo skipDependencyCheck: SkipDependencyCheck, authenticodeCheck: AuthenticodeCheck, savePkg: false, - pathsToInstallPkg: _pathsToInstallPkg); + pathsToInstallPkg: _pathsToInstallPkg, + tmpPath: _tmpPath); if (PassThru) { diff --git a/src/code/SavePSResource.cs b/src/code/SavePSResource.cs index 3f2b2ce26..9c92a261f 100644 --- a/src/code/SavePSResource.cs +++ b/src/code/SavePSResource.cs @@ -109,6 +109,30 @@ public string Path } private string _path; + /// + /// The destination where the resource is to be temporarily saved to. + + /// + [Parameter] + [ValidateNotNullOrEmpty] + public string TemporaryPath + { + get + { return _tmpPath; } + + set + { + if (WildcardPattern.ContainsWildcardCharacters(value)) + { + throw new PSArgumentException("Wildcard characters are not allowed in the temporary path."); + } + + // This will throw if path cannot be resolved + _tmpPath = SessionState.Path.GetResolvedPSPathFromPSPath(value).First().Path; + } + } + private string _tmpPath; + /// /// Suppresses being prompted for untrusted sources. /// @@ -266,7 +290,8 @@ private void ProcessSaveHelper(string[] pkgNames, bool pkgPrerelease, string[] p skipDependencyCheck: SkipDependencyCheck, authenticodeCheck: AuthenticodeCheck, savePkg: true, - pathsToInstallPkg: new List { _path }); + pathsToInstallPkg: new List { _path }, + tmpPath: _tmpPath); if (PassThru) { diff --git a/src/code/UpdatePSResource.cs b/src/code/UpdatePSResource.cs index bce9ed295..c670c0afe 100644 --- a/src/code/UpdatePSResource.cs +++ b/src/code/UpdatePSResource.cs @@ -5,6 +5,7 @@ using NuGet.Versioning; using System; using System.Collections.Generic; +using System.IO; using System.Linq; using System.Management.Automation; using System.Threading; @@ -68,6 +69,30 @@ public sealed class UpdatePSResource : PSCmdlet [Parameter] public ScopeType Scope { get; set; } + /// + /// The destination where the resource is to be temporarily installed to while updating. + + /// + [Parameter] + [ValidateNotNullOrEmpty] + public string TemporaryPath + { + get + { return _tmpPath; } + + set + { + if (WildcardPattern.ContainsWildcardCharacters(value)) + { + throw new PSArgumentException("Wildcard characters are not allowed in the temporary path."); + } + + // This will throw if path cannot be resolved + _tmpPath = SessionState.Path.GetResolvedPSPathFromPSPath(value).First().Path; + } + } + private string _tmpPath; + /// /// When specified, suppresses prompting for untrusted sources. /// @@ -187,7 +212,8 @@ protected override void ProcessRecord() skipDependencyCheck: SkipDependencyCheck, authenticodeCheck: AuthenticodeCheck, savePkg: false, - pathsToInstallPkg: _pathsToInstallPkg); + pathsToInstallPkg: _pathsToInstallPkg, + tmpPath: _tmpPath); if (PassThru) {