Skip to content

[WIP] Experiment on getting GitHub Packages packages correct casing #1855

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
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
33 changes: 30 additions & 3 deletions src/code/InstallHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,7 @@ private bool TryInstallToTempPath(
try
{
var pathToFile = Path.Combine(tempInstallPath, $"{pkgName}.{normalizedPkgVersion}.zip");
using var fs = File.Create(pathToFile);
using FileStream fs = File.Create(pathToFile);
responseStream.Seek(0, System.IO.SeekOrigin.Begin);
responseStream.CopyTo(fs);
fs.Close();
Expand All @@ -943,8 +943,8 @@ private bool TryInstallToTempPath(

File.Delete(pathToFile);

var moduleManifest = Path.Combine(tempDirNameVersion, pkgName + PSDataFileExt);
var scriptPath = Path.Combine(tempDirNameVersion, pkgName + PSScriptFileExt);
string moduleManifest = Path.Combine(tempDirNameVersion, pkgName + PSDataFileExt);
string scriptPath = Path.Combine(tempDirNameVersion, pkgName + PSScriptFileExt);

bool isModule = File.Exists(moduleManifest);
bool isScript = File.Exists(scriptPath);
Expand Down Expand Up @@ -980,6 +980,15 @@ private bool TryInstallToTempPath(
return false;
}

// Get module actual name with correct casing
string moduleManifestActualFileName = Path.GetFileNameWithoutExtension(
Directory.GetFiles(
tempDirNameVersion,
$"{pkgName}.psd1"
)[0]
);
_cmdletPassedIn.WriteVerbose($"pkgName: \"{pkgName}\", actual name of manifest: \"${moduleManifestActualFileName}");

if (!Utils.TryReadManifestFile(
manifestFilePath: moduleManifest,
manifestInfo: out Hashtable parsedMetadataHashtable,
Expand Down Expand Up @@ -1032,6 +1041,15 @@ private bool TryInstallToTempPath(

return false;
}

// Get script actual name with correct casing
string scriptActualFileName = Path.GetFileNameWithoutExtension(
Directory.GetFiles(
tempDirNameVersion,
$"{pkgName}.ps1"
)[0]
);
_cmdletPassedIn.WriteVerbose($"pkgName: \"{pkgName}\", actual name of script: \"{scriptActualFileName}\"");
}
else
{
Expand All @@ -1040,6 +1058,15 @@ private bool TryInstallToTempPath(

_cmdletPassedIn.WriteVerbose($"This resource is not a PowerShell package and will be installed to the modules path: {installPath}.");
isModule = true;

// Get actual name from .nuspec file
string resourceNuspecFileName = Path.GetFileNameWithoutExtension(
Directory.GetFiles(
tempDirNameVersion,
$"{pkgName}.nuspec"
)[0]
);
_cmdletPassedIn.WriteVerbose($"pkgName: \"{pkgName}\", actual name of nuspec file: \"{resourceNuspecFileName}\"");
}

installPath = _savePkg ? _pathsToInstallPkg.First() : installPath;
Expand Down
4 changes: 2 additions & 2 deletions src/code/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1343,8 +1343,8 @@ private static bool TryReadPSDataFile(
throw new PSArgumentNullException(nameof(filePath));
}

string contents = System.IO.File.ReadAllText(filePath);
var scriptBlock = System.Management.Automation.ScriptBlock.Create(contents);
string contents = File.ReadAllText(filePath);
var scriptBlock = ScriptBlock.Create(contents);

// Ensure that the content script block is safe to convert into a PSDataFile Hashtable.
// This will throw for unsafe content.
Expand Down