Skip to content
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
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
5 changes: 4 additions & 1 deletion src/code/InstallHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ private Hashtable BeginPackageInstall(
{
return packagesHash;
}

pkgToInstall.RepositorySourceLocation = repository.Uri.ToString();
pkgToInstall.AdditionalMetadata.TryGetValue("NormalizedVersion", out string pkgVersion);
if (pkgVersion == null) {
Expand Down Expand Up @@ -972,6 +972,8 @@ private bool TryInstallToTempPath(
try
{
var pathToFile = Path.Combine(tempInstallPath, $"{pkgName}.{normalizedPkgVersion}.zip");
_cmdletPassedIn.WriteVerbose($"pathToFile IS: {pathToFile}.");

using var fs = File.Create(pathToFile);
responseStream.Seek(0, System.IO.SeekOrigin.Begin);
responseStream.CopyTo(fs);
Expand All @@ -980,6 +982,7 @@ private bool TryInstallToTempPath(
// Expand the zip file
var pkgVersion = pkgToInstall.Version.ToString();
var tempDirNameVersion = Path.Combine(tempInstallPath, pkgName.ToLower(), pkgVersion);

Directory.CreateDirectory(tempDirNameVersion);

if (!TryExtractToDirectory(pathToFile, tempDirNameVersion, out error))
Expand Down
6 changes: 3 additions & 3 deletions src/code/LocalServerApiCalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,7 @@ private Hashtable GetMetadataFromNupkg(string packageName, string packagePath, s
string psd1FilePath = String.Empty;
string ps1FilePath = String.Empty;
string nuspecFilePath = String.Empty;
Utils.GetMetadataFilesFromPath(tempDiscoveryPath, packageName, out psd1FilePath, out ps1FilePath, out nuspecFilePath);
Utils.GetMetadataFilesFromPath(tempDiscoveryPath, packageName, out psd1FilePath, out ps1FilePath, out nuspecFilePath, out string properCasingPkgName);

List<string> pkgTags = new List<string>();

Expand All @@ -710,7 +710,7 @@ private Hashtable GetMetadataFromNupkg(string packageName, string packagePath, s
pkgMetadata.Add("ProjectUri", projectUri);
pkgMetadata.Add("IconUri", iconUri);
pkgMetadata.Add("ReleaseNotes", releaseNotes);
pkgMetadata.Add("Id", packageName);
pkgMetadata.Add("Id", properCasingPkgName);
pkgMetadata.Add(_fileTypeKey, Utils.MetadataFileType.ModuleManifest);

pkgTags.AddRange(pkgHashTags);
Expand All @@ -730,7 +730,7 @@ private Hashtable GetMetadataFromNupkg(string packageName, string packagePath, s
}

pkgMetadata = parsedScript.ToHashtable();
pkgMetadata.Add("Id", packageName);
pkgMetadata.Add("Id", properCasingPkgName);
pkgMetadata.Add(_fileTypeKey, Utils.MetadataFileType.ScriptFile);
pkgTags.AddRange(pkgMetadata["Tags"] as string[]);

Expand Down
18 changes: 16 additions & 2 deletions src/code/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1172,11 +1172,12 @@ internal static HashSet<string> GetInstalledPackages(List<string> pathsToSearch,
return pkgsInstalledOnMachine;
}

internal static void GetMetadataFilesFromPath(string dirPath, string packageName, out string psd1FilePath, out string ps1FilePath, out string nuspecFilePath)
internal static void GetMetadataFilesFromPath(string dirPath, string packageName, out string psd1FilePath, out string ps1FilePath, out string nuspecFilePath, out string properCasingPkgName)
{
psd1FilePath = String.Empty;
ps1FilePath = String.Empty;
nuspecFilePath = String.Empty;
properCasingPkgName = packageName;

var discoveredFiles = Directory.GetFiles(dirPath, "*.*", SearchOption.AllDirectories);
string pkgNamePattern = $"{packageName}*";
Expand All @@ -1185,16 +1186,29 @@ internal static void GetMetadataFilesFromPath(string dirPath, string packageName
{
if (rgx.IsMatch(file))
{
if (file.EndsWith("psd1"))
string fileName = Path.GetFileName(file);
if (fileName.EndsWith("psd1"))
{
if (string.Compare($"{packageName}.psd1", fileName, StringComparison.OrdinalIgnoreCase) == 0)
{
properCasingPkgName = Path.GetFileNameWithoutExtension(file);
}
psd1FilePath = file;
}
else if (file.EndsWith("nuspec"))
{
if (string.Compare($"{packageName}.nuspec", fileName, StringComparison.OrdinalIgnoreCase) == 0)
{
properCasingPkgName = Path.GetFileNameWithoutExtension(file);
}
nuspecFilePath = file;
}
else if (file.EndsWith("ps1"))
{
if (string.Compare($"{packageName}.ps1", fileName, StringComparison.OrdinalIgnoreCase) == 0)
{
properCasingPkgName = Path.GetFileNameWithoutExtension(file);
}
ps1FilePath = file;
}
}
Expand Down
29 changes: 8 additions & 21 deletions test/InstallPSResourceTests/InstallPSResourceLocal.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -140,38 +140,25 @@ Describe 'Test Install-PSResource for local repositories' -tags 'CI' {
}

It "Install resource with cmdlet names from a module already installed with -NoClobber (should not clobber)" {
Install-PSResource -Name $testModuleClobber -Repository $localRepo -TrustRepository
Install-PSResource -Name $testModuleClobber -Repository $localRepo -TrustRepository -Verbose
$pkg = Get-InstalledPSResource $testModuleClobber
$pkg.Name | Should -Be $testModuleClobber
$pkg.Version | Should -Be "1.0.0"


# Get the first available module named 'clobbertestmodule1' and its exported commands
$module = (Get-Module -ListAvailable $testModuleClobber)
Write-Verbose -Verbose "Module Name: $($module.Name)"
$moduleIdx = $module[0]

# Iterate through each exported command in the module
foreach ($command in $moduleIdx.ExportedCommands.Values) {
# Output the command's name and details
Write-Verbose -Verbose "Command Name: $($command.Name)"
Write-Verbose -Verbose "Command Type: $($command.CommandType)"
Write-Verbose -Verbose "----------------------------------"
}


Install-PSResource -Name $testModuleClobber2 -Repository $localRepo -TrustRepository -NoClobber -ErrorVariable ev -ErrorAction SilentlyContinue -verbose
$pkg = Get-InstalledPSResource $testModuleClobber2 -ErrorAction SilentlyContinue

# Get the first available module named 'clobbertestmodule1' and its exported commands
$module2 = (Get-Module -ListAvailable $testModuleClobber2)[0]
$module2Idx = $module[0]
# Iterate through each exported command in the module
foreach ($command in $module2Idx.ExportedCommands.Values) {
if (!$pkg) {
# Get the first available module named 'clobbertestmodule1' and its exported commands
$module2 = (Get-Module -ListAvailable $testModuleClobber2)[0]
$module2Idx = $module[0]
# Iterate through each exported command in the module
foreach ($command in $module2Idx.ExportedCommands.Values) {
# Output the command's name and details
Write-Verbose -Verbose "Command Name: $($command.Name)"
Write-Verbose -Verbose "Command Type: $($command.CommandType)"
Write-Verbose -Verbose "----------------------------------"
}
}

$pkg | Should -BeNullOrEmpty
Expand Down
Loading