Skip to content
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: 31 additions & 2 deletions src/code/InstallHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1028,8 +1028,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 @@ -1066,6 +1066,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 @@ -1118,12 +1127,32 @@ 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
{
// This package is not a PowerShell package (eg a resource from the NuGet Gallery).
installPath = _pathsToInstallPkg.Find(path => path.EndsWith("Modules", StringComparison.InvariantCultureIgnoreCase));

_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}\"");
// TODO: pass in ConcurrentQueue to write out verbose message.
// _cmdletPassedIn.WriteVerbose($"This resource is not a PowerShell package and will be installed to the modules path: {installPath}.");
isModule = true;
Expand Down
2 changes: 1 addition & 1 deletion src/code/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1394,7 +1394,7 @@ private static bool TryReadPSDataFile(
{
throw new PSArgumentNullException(nameof(filePath));
}
string contents = System.IO.File.ReadAllText(filePath);
string contents = File.ReadAllText(filePath);

// Validate that the file content conforms to restricted language rules before execution.
// This parses the content into an AST and statically validates it only contains data-file-safe constructs (hashtables, arrays, literals, etc).
Expand Down